public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-dev] [PATCH] python-utils-r1.eclass: Use @a instead of declare check for array
@ 2023-06-16  4:26 Michał Górny
  0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2023-06-16  4:26 UTC (permalink / raw
  To: gentoo-dev; +Cc: Michał Górny

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



^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-06-16  4:26 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-16  4:26 [gentoo-dev] [PATCH] python-utils-r1.eclass: Use @a instead of declare check for array Michał Górny

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox