commit: b5feaf2444ae625f5756c7566042d28f81a2cda1 Author: Kerin Millar <kfm <AT> plushkava <DOT> net> AuthorDate: Wed May 22 05:54:12 2024 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Wed May 22 16:27:00 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=b5feaf24
Micro-optimise the eqatag() argument parsing loop Signed-off-by: Kerin Millar <kfm <AT> plushkava.net> functions.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/functions.sh b/functions.sh index 98e7a6f..f965534 100644 --- a/functions.sh +++ b/functions.sh @@ -187,7 +187,7 @@ eoutdent() # eqatag() { - local arg argc json positional tag + local arg i json positional tag case ${genfun_has_jq} in 0) @@ -211,11 +211,14 @@ eqatag() if [ "$#" -eq 0 ]; then die "eqatag: no tag specified" fi + positional=0 tag=$1 shift - argc=$# - positional=0 + i=0 for arg; do + if [ "$(( i += 1 ))" -eq 1 ]; then + set -- + fi case ${arg} in [!=/]*=?*) if [ "${positional}" -eq 1 ]; then @@ -234,7 +237,6 @@ eqatag() _throw_invalid_args eqatag "${arg}" esac done - shift "${argc}" json=$( jq -cn '{ eqatag: {