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 7D0D9158008 for ; Fri, 16 Jun 2023 12:08:47 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 2220DE0980; Fri, 16 Jun 2023 12:07:48 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (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 BF55AE0976 for ; Fri, 16 Jun 2023 12:07:47 +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 3/5] cargo.eclass: Optimize GIT_CRATES check Date: Fri, 16 Jun 2023 14:01:06 +0200 Message-ID: <20230616120739.8656-4-mgorny@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230616120739.8656-1-mgorny@gentoo.org> References: <20230616120739.8656-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: da525645-55fc-4e1b-995a-123d195bda69 X-Archives-Hash: b46f1b172f2edb647e4e81abb3a2b9a5 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