• [gentoo-dev] [PATCH] python-utils-r1.eclass: Use @a instead of declare

    From =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?@21:1/5 to All on Fri Jun 16 06:30:02 2023
    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>
    ---
    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=()
    --
    2.41.0

    --- SoupGa