summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-06-15 17:23:21 +0200
committerMichał Górny <mgorny@gentoo.org>2023-06-18 16:57:45 +0200
commit12ab6ca3d654d25a79c8ef8a40c1d5a2ed671771 (patch)
treea599f863d7c72b167411b77de15d94263ea74b30 /eclass
parentcargo.eclass: Add variable alternative to $(cargo_crate_uris) (diff)
downloadgentoo-12ab6ca3d654d25a79c8ef8a40c1d5a2ed671771.tar.gz
gentoo-12ab6ca3d654d25a79c8ef8a40c1d5a2ed671771.tar.bz2
gentoo-12ab6ca3d654d25a79c8ef8a40c1d5a2ed671771.zip
cargo.eclass: Optimize GIT_CRATES check
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>
Diffstat (limited to 'eclass')
-rw-r--r--eclass/cargo.eclass58
1 files 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}"