diff options
author | Michał Górny <mgorny@gentoo.org> | 2023-06-15 14:29:55 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2023-06-17 12:10:15 +0200 |
commit | 4d7804af0ce9077cbc53cda7318a3e388db8dbb3 (patch) | |
tree | 20f3f5ae466e9fe6a30da7ca62312dd0eba7bf02 /eclass/python-utils-r1.eclass | |
parent | eclass/tests: Add a benchmark for python-utils-r1 (diff) | |
download | gentoo-4d7804af0ce9077cbc53cda7318a3e388db8dbb3.tar.gz gentoo-4d7804af0ce9077cbc53cda7318a3e388db8dbb3.tar.bz2 gentoo-4d7804af0ce9077cbc53cda7318a3e388db8dbb3.zip |
python-utils-r1.eclass: Use @a instead of declare check for array
Use bash 5's @a variable substitution instead of `declare -p` check
to determine if `PYTHON_COMPAT` is an array. This avoids a subshell,
and effectively makes the function roughly 3.5x faster:
```
* Timing _python_set_impls
real 4854 it/s
user 4862 it/s
```
In practice, this roughly reduces total sourcing time for `dev-python/*`
from 57-58 s to 54 s.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Closes: https://github.com/gentoo/gentoo/pull/31454
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/python-utils-r1.eclass')
-rw-r--r-- | eclass/python-utils-r1.eclass | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass index 52e9e061d6bd..7a1be381f596 100644 --- a/eclass/python-utils-r1.eclass +++ b/eclass/python-utils-r1.eclass @@ -114,11 +114,18 @@ _python_verify_patterns() { _python_set_impls() { local i - if ! declare -p PYTHON_COMPAT &>/dev/null; then - die 'PYTHON_COMPAT not declared.' + # TODO: drop BASH_VERSINFO check when we require EAPI 8 + if [[ ${BASH_VERSINFO[0]} -ge 5 ]]; then + [[ ${PYTHON_COMPAT@a} == *a* ]] + else + [[ $(declare -p PYTHON_COMPAT) == "declare -a"* ]] fi - if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then - die 'PYTHON_COMPAT must be an array.' + if [[ ${?} -ne 0 ]]; then + if ! declare -p PYTHON_COMPAT &>/dev/null; then + die 'PYTHON_COMPAT not declared.' + else + die 'PYTHON_COMPAT must be an array.' + fi fi local obsolete=() |