From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 3E28F158008 for ; Fri, 16 Jun 2023 04:26:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 188E1E09EC; Fri, 16 Jun 2023 04:26:13 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id D705DE09E4 for ; Fri, 16 Jun 2023 04:26:12 +0000 (UTC) From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= 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 Message-ID: <20230616042607.242388-1-mgorny@gentoo.org> X-Mailer: git-send-email 2.41.0 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Archives-Salt: f249ff28-30e3-4154-9793-fe2365802b98 X-Archives-Hash: bf2830b3cf4bb7436aaffb9e8ad818c6 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 --- 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