commit: 4d7804af0ce9077cbc53cda7318a3e388db8dbb3 Author: Michał Górny <mgorny <AT> gentoo <DOT> org> AuthorDate: Thu Jun 15 12:29:55 2023 +0000 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> CommitDate: Sat Jun 17 10:10:15 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4d7804af
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 <AT> gentoo.org> Closes: https://github.com/gentoo/gentoo/pull/31454 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> eclass/python-utils-r1.eclass | 15 +++++++++++---- 1 file 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=()
