From 64efe7ffaff84522e6b0089d27ec8fd31b51e36a Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 10 Apr 2025 19:50:56 +0000 Subject: [PATCH] utils/namesub: make regex chain instead of looping over them --- utils/name_substitution.sh | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/utils/name_substitution.sh b/utils/name_substitution.sh index c137f79f..781c8323 100755 --- a/utils/name_substitution.sh +++ b/utils/name_substitution.sh @@ -11,6 +11,8 @@ REGEXES=( 's/(?:Google )?Chrom(e|ium)(?!\w)/Helium/g' ) +REGEX_CHAIN=$(IFS=';'; echo "${REGEXES[*]}") + sanity_check() { if ! [ -f OWNERS ]; then echo "wrong src directory" >&2 @@ -47,10 +49,7 @@ do_sub() { fi cp "$file_path" "$file_path.new" - - for regex in "${REGEXES[@]}"; do - perl -pi -e "$regex" "$file_path.new" - done + perl -pi -e "$REGEX_CHAIN" "$file_path.new" diff -Naur "$file_path" "$file_path.new" || true mv "$file_path.new" "$file_path" @@ -70,13 +69,7 @@ do_unsub() { } do_str() { - STR="$1" - - for regex in "${REGEXES[@]}"; do - STR="$(perl -ne "$regex; print;" <<< "$STR")" - done - - echo "$STR" + perl -pe "$REGEX_CHAIN" <<< "$1" } case $ACTION in