commit: 0fbe3a4835e538969c5818ca6bece91de933a8de
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun May 19 14:56:18 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun May 19 14:56:18 2024 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=0fbe3a48
Micro-optimise _print_args()
Optimise _print_args() by initialising the ord_by array lazily.
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 0f0aa44..f2e5bb5 100644
--- a/functions.sh
+++ b/functions.sh
@@ -535,10 +535,6 @@ _is_visible()
_print_args() {
awk -v q=\' -f - -- "$@" <<-'EOF'
BEGIN {
- for (i = 1; i < 32; i++) {
- char = sprintf("%c", i)
- ord_by[char] = i
- }
argc = ARGC
ARGC = 1
for (arg_idx = 1; arg_idx < argc; arg_idx++) {
@@ -548,6 +544,12 @@ _print_args() {
word = q arg q
} else {
# Use $'' quoting per Issue 8
+ if (ord_by["\001"] == "") {
+ for (i = 1; i < 32; i++) {
+ char = sprintf("%c", i)
+ ord_by[char] = i
+ }
+ }
word = "$'"
for (i = 1; i <= length(arg); i++) {
char = substr(arg, i, 1)