public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: Sam James <sam@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: ruby@gentoo.org, Sam James <sam@gentoo.org>
Subject: [gentoo-dev] [PATCH 04/11] ruby-ng.eclass: optimize: avoid subshells for _ruby_atoms_samelib*
Date: Thu, 15 Jun 2023 16:52:31 +0100	[thread overview]
Message-ID: <20230615155240.589982-4-sam@gentoo.org> (raw)
In-Reply-To: <20230615155240.589982-1-sam@gentoo.org>

- Inline ruby_atoms_samelib (only used by one caller)
- Avoid repeated (subshell) calls to _ruby_atoms_samelib_generic by using a result
  variable instead.

We go from 3.5s -> 2.5s to source dev-ruby/*.

Thanks to mgorny for the ideas here.

Bug: https://bugs.gentoo.org/908465
Signed-off-by: Sam James <sam@gentoo.org>
---
 eclass/ruby-ng.eclass | 57 ++++++++++++++++++++++---------------------
 1 file changed, 29 insertions(+), 28 deletions(-)

diff --git a/eclass/ruby-ng.eclass b/eclass/ruby-ng.eclass
index ee2e6b89edb41..cf66fcec2f05d 100644
--- a/eclass/ruby-ng.eclass
+++ b/eclass/ruby-ng.eclass
@@ -141,23 +141,6 @@ ruby_samelib() {
 	echo "[${res%,}]"
 }
 
-_ruby_atoms_samelib_generic() {
-	eshopts_push -o noglob
-	echo "RUBYTARGET? ("
-	for token in $*; do
-		case "$token" in
-			"||" | "(" | ")" | *"?")
-				echo "${token}" ;;
-			*])
-				echo "${token%[*}[RUBYTARGET(-),${token/*[}" ;;
-			*)
-				echo "${token}[RUBYTARGET(-)]" ;;
-		esac
-	done
-	echo ")"
-	eshopts_pop
-}
-
 # @FUNCTION: ruby_implementation_command
 # @RETURN: the path to the given ruby implementation
 # @DESCRIPTION:
@@ -173,11 +156,29 @@ ruby_implementation_command() {
 	echo $(type -p ${_ruby_name} 2>/dev/null)
 }
 
+_RUBY_ATOMS_SAMELIB_RESULT=""
 _ruby_atoms_samelib() {
-	local atoms=$(_ruby_atoms_samelib_generic "$*")
+	_RUBY_ATOMS_SAMELIB_RESULT=""
+
+	eshopts_push -o noglob
+	local token
+	local atoms=" RUBYTARGET? ("
+	for token in $*; do
+		case "${token}" in
+			"||" | "(" | ")" | *"?")
+				atoms+=" ${token}" ;;
+			*])
+				atoms+=" ${token%[*}[RUBYTARGET(-),${token/*[}" ;;
+			*)
+				atoms+=" ${token}[RUBYTARGET(-)]" ;;
+		esac
+	done
+	atoms+=" ) "
+	eshopts_pop
 
+	local _ruby_implementation
 	for _ruby_implementation in "${_RUBY_GET_ALL_IMPLS[@]}"; do
-		echo "${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
+		_RUBY_ATOMS_SAMELIB_RESULT+="${atoms//RUBYTARGET/ruby_targets_${_ruby_implementation}}"
 	done
 }
 
@@ -226,15 +227,15 @@ ruby_add_rdepend() {
 			;;
 	esac
 
-	local dependency=$(_ruby_atoms_samelib "$1")
+	_ruby_atoms_samelib "$1"
 
-	RDEPEND="${RDEPEND} $dependency"
+	RDEPEND="${RDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}"
 
 	# Add the dependency as a test-dependency since we're going to
 	# execute the code during test phase.
 	case ${EAPI} in
-		6) DEPEND="${DEPEND} test? ( ${dependency} )" ;;
-		*) BDEPEND="${BDEPEND} test? ( ${dependency} )" ;;
+		6) DEPEND="${DEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;;
+		*) BDEPEND="${BDEPEND} test? ( ${_RUBY_ATOMS_SAMELIB_RESULT} )" ;;
 	esac
 	if ! has test "$IUSE"; then
 		IUSE+=" test"
@@ -273,11 +274,11 @@ ruby_add_bdepend() {
 			;;
 	esac
 
-	local dependency=$(_ruby_atoms_samelib "$1")
+	_ruby_atoms_samelib "$1"
 
 	case ${EAPI} in
-		6) DEPEND="${DEPEND} $dependency" ;;
-		*) BDEPEND="${BDEPEND} $dependency" ;;
+		6) DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;;
+		*) BDEPEND="${BDEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}" ;;
 	esac
 	RDEPEND="${RDEPEND}"
 }
@@ -300,9 +301,9 @@ ruby_add_depend() {
 		*) die "bad number of arguments to $0" ;;
 	esac
 
-	local dependency=$(_ruby_atoms_samelib "$1")
+	_ruby_atoms_samelib "$1"
 
-	DEPEND="${DEPEND} $dependency"
+	DEPEND="${DEPEND} ${_RUBY_ATOMS_SAMELIB_RESULT}"
 }
 
 # @FUNCTION: ruby_get_use_implementations
-- 
2.41.0



  parent reply	other threads:[~2023-06-15 15:53 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-15 15:52 [gentoo-dev] [PATCH 01/11] ruby-ng.eclass: optimize: use pattern for old ruby impls Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 02/11] ruby-ng.eclass: optimize: use pattern substitution Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 03/11] ruby-ng.eclass: optimize: avoid subshell for ruby_get_all_impls Sam James
2023-06-15 15:52 ` Sam James [this message]
2023-06-15 15:52 ` [gentoo-dev] [PATCH 05/11] ruby-ng.eclass: optimize: avoid subshells for ruby_implementations_depend, ruby_get_use_targets Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 06/11] ruby-ng.eclass: use bash += Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 07/11] ruby-ng.eclass: use bash tests Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 08/11] ruby-ng.eclass: drop no-op RDEPEND assignment Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 09/11] ruby-ng.eclass: cater to USE_RUBY conditional calls Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 10/11] ruby-ng.eclass: use shopt directly, not via estack.eclass Sam James
2023-06-15 16:27   ` Petr Vaněk
2023-06-15 21:12     ` Sam James
2023-06-15 18:07   ` Hans de Graaff
2023-06-15 21:11     ` Sam James
2023-06-15 15:52 ` [gentoo-dev] [PATCH 11/11] ruby-ng.eclass: add _ruby_get_use_targets comment Sam James
2023-06-15 18:08 ` [gentoo-dev] [PATCH 01/11] ruby-ng.eclass: optimize: use pattern for old ruby impls Hans de Graaff
2023-06-15 21:12   ` Sam James

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=20230615155240.589982-4-sam@gentoo.org \
    --to=sam@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    --cc=ruby@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