commit: 676e6dc3f4a921d4fcb1e320e7d0562e2ef08856 Author: Sam James <sam <AT> gentoo <DOT> org> AuthorDate: Tue Jun 13 21:59:47 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Thu Jun 15 21:12:16 2023 +0000 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=676e6dc3
ruby-ng.eclass: optimize: avoid subshells for _ruby_atoms_samelib* - 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 <AT> 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 ee2e6b89edb4..cf66fcec2f05 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