From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH] python-utils-r1.eclass: Use @a instead of declare check for array
Date: Fri, 16 Jun 2023 06:26:07 +0200 [thread overview]
Message-ID: <20230616042607.242388-1-mgorny@gentoo.org> (raw)
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
reply other threads:[~2023-06-16 4:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230616042607.242388-1-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