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 1416D158008 for ; Tue, 13 Jun 2023 06:49:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0BF0FE09C1; Tue, 13 Jun 2023 06:47:53 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id C35CAE09BD for ; Tue, 13 Jun 2023 06:47:52 +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 5/7] pypi.eclass: Translate version without subshell in common case Date: Tue, 13 Jun 2023 08:45:05 +0200 Message-ID: <20230613064742.413335-6-mgorny@gentoo.org> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230613064742.413335-1-mgorny@gentoo.org> References: <20230613064742.413335-1-mgorny@gentoo.org> 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: e392bb50-1a7e-4afe-93f6-d3f7be315248 X-Archives-Hash: b6ffce0cfec4a678c37db386ec3ceef9 Provide an internal helper to translate versions without a subshell, and use it in the common case. Now the benchmark gives 685 ops / s, which means it's another 28% speedup. Signed-off-by: Michał Górny --- eclass/pypi.eclass | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass index d79e6f06fc1b..c8ad2e03d6e8 100644 --- a/eclass/pypi.eclass +++ b/eclass/pypi.eclass @@ -95,6 +95,19 @@ pypi_normalize_name() { echo "${_PYPI_NORMALIZED_NAME}" } +# @FUNCTION: _pypi_translate_version +# @USAGE: +# @DESCRIPTION: +# Internal version translation function, returns the result +# via _PYPI_TRANSLATED_VERSION variable. +_pypi_translate_version() { + local version=${1} + version=${version/_alpha/a} + version=${version/_beta/b} + version=${version/_rc/rc} + _PYPI_TRANSLATED_VERSION=${version/_p/.post} +} + # @FUNCTION: pypi_translate_version # @USAGE: # @DESCRIPTION: @@ -106,12 +119,9 @@ pypi_normalize_name() { pypi_translate_version() { [[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} " - local version=${1} - version=${version/_alpha/a} - version=${version/_beta/b} - version=${version/_rc/rc} - version=${version/_p/.post} - echo "${version}" + local _PYPI_TRANSLATED_VERSION + _pypi_translate_version "${@}" + echo "${_PYPI_TRANSLATED_VERSION}" } # @FUNCTION: pypi_sdist_url @@ -239,16 +249,17 @@ pypi_wheel_url() { # @DESCRIPTION: # Set global variables, SRC_URI and S. _pypi_set_globals() { - local version=$(pypi_translate_version "${PV}") + local _PYPI_TRANSLATED_VERSION + _pypi_translate_version "${PV}" if [[ ${PYPI_NO_NORMALIZE} ]]; then - SRC_URI="$(pypi_sdist_url --no-normalize "${PYPI_PN}" "${version}")" + SRC_URI="$(pypi_sdist_url --no-normalize "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}")" S="${WORKDIR}/${PYPI_PN}-${version}" else local _PYPI_NORMALIZED_NAME _pypi_normalize_name "${PYPI_PN}" - SRC_URI="$(pypi_sdist_url "${PYPI_PN}" "${version}")" - S="${WORKDIR}/${_PYPI_NORMALIZED_NAME}-${version}" + SRC_URI="$(pypi_sdist_url "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}")" + S="${WORKDIR}/${_PYPI_NORMALIZED_NAME}-${_PYPI_TRANSLATED_VERSION}" fi } -- 2.41.0