From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 3/5] cargo.eclass: Optimize GIT_CRATES check
Date: Fri, 16 Jun 2023 14:01:06 +0200 [thread overview]
Message-ID: <20230616120739.8656-4-mgorny@gentoo.org> (raw)
In-Reply-To: <20230616120739.8656-1-mgorny@gentoo.org>
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 <mgorny@gentoo.org>
---
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
next prev parent reply other threads:[~2023-06-16 12:08 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 12:01 [gentoo-dev] [PATCH 0/5] cargo.eclass: optimizations Michał Górny
2023-06-16 12:01 ` [gentoo-dev] [PATCH 1/5] eclass/tests: Add a minimal benchmark for cargo.eclass Michał Górny
2023-06-16 12:01 ` [gentoo-dev] [PATCH 2/5] cargo.eclass: Add variable alternative to $(cargo_crate_uris) Michał Górny
2023-06-16 12:01 ` Michał Górny [this message]
2023-06-16 12:01 ` [gentoo-dev] [PATCH 4/5] cargo.eclass: Support separating crate names/versions via slash Michał Górny
2023-06-16 14:48 ` Denis Lisov
2023-06-16 15:52 ` Michał Górny
2023-06-16 18:06 ` Sam James
2023-06-16 12:01 ` [gentoo-dev] [PATCH 5/5] cargo.eclass: Mark GIT_CRATES as pre-inherit Michał Górny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230616120739.8656-4-mgorny@gentoo.org \
--to=mgorny@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox