From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 569C6158008 for ; Fri, 16 Jun 2023 19:21:57 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id EB1D9E0931; Fri, 16 Jun 2023 19:20:58 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id B06F5E092C for ; Fri, 16 Jun 2023 19:20:58 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= Subject: [gentoo-dev] [PATCH v2 3/5] cargo.eclass: Optimize GIT_CRATES check Date: Fri, 16 Jun 2023 21:19:56 +0200 Message-ID: <20230616192050.9828-4-mgorny@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616192050.9828-1-mgorny@gentoo.org> References: <20230616192050.9828-1-mgorny@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: bff2bd84-012f-49e2-9b70-9c64f8fcba1b X-Archives-Hash: 7fe9d0fe9667962ed88036fdc4ae47fd Optimize the GIT_CRATES check to call `declare -p` only if the variable is actually set. In the vast majority of ebuilds using cargo.eclass, it's not set, so the subshell-first approach is slowing things down. With this change, the speed improves by another ~20%: ``` real 363 it/s user 365 it/s ``` Signed-off-by: Michał Górny --- eclass/cargo.eclass | 58 ++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/eclass/cargo.eclass b/eclass/cargo.eclass index 4e0cd1e4de70..d97bb0df9348 100644 --- a/eclass/cargo.eclass +++ b/eclass/cargo.eclass @@ -189,35 +189,35 @@ _cargo_set_crate_uris() { CARGO_CRATE_URIS+="${url} " done - local git_crates_type - git_crates_type="$(declare -p GIT_CRATES 2>&-)" - if [[ ${git_crates_type} == "declare -A "* ]]; then - local crate commit crate_uri crate_dir repo_ext feat_expr - - for crate in "${!GIT_CRATES[@]}"; do - IFS=';' read -r crate_uri commit crate_dir <<< "${GIT_CRATES[${crate}]}" - - case "${crate_uri}" in - https://github.com/*) - repo_ext=".gh" - repo_name="${crate_uri##*/}" - crate_uri="${crate_uri%/}/archive/%commit%.tar.gz" - ;; - https://gitlab.com/*) - repo_ext=".gl" - repo_name="${crate_uri##*/}" - crate_uri="${crate_uri%/}/-/archive/%commit%/${repo_name}-%commit%.tar.gz" - ;; - *) - repo_ext= - repo_name="${crate}" - ;; - esac - - CARGO_CRATE_URIS+="${crate_uri//%commit%/${commit}} -> ${repo_name}-${commit}${repo_ext}.tar.gz " - done - elif [[ -n ${git_crates_type} ]]; then - die "GIT_CRATE must be declared as an associative array" + if declare -p GIT_CRATES &>/dev/null; then + if [[ $(declare -p GIT_CRATES) == "declare -A"* ]]; then + local crate commit crate_uri crate_dir repo_ext feat_expr + + for crate in "${!GIT_CRATES[@]}"; do + IFS=';' read -r crate_uri commit crate_dir <<< "${GIT_CRATES[${crate}]}" + + case "${crate_uri}" in + https://github.com/*) + repo_ext=".gh" + repo_name="${crate_uri##*/}" + crate_uri="${crate_uri%/}/archive/%commit%.tar.gz" + ;; + https://gitlab.com/*) + repo_ext=".gl" + repo_name="${crate_uri##*/}" + crate_uri="${crate_uri%/}/-/archive/%commit%/${repo_name}-%commit%.tar.gz" + ;; + *) + repo_ext= + repo_name="${crate}" + ;; + esac + + CARGO_CRATE_URIS+="${crate_uri//%commit%/${commit}} -> ${repo_name}-${commit}${repo_ext}.tar.gz " + done + else + die "GIT_CRATE must be declared as an associative array" + fi fi } _cargo_set_crate_uris "${CRATES}" -- 2.41.0