From bbce69f036a3553380ce0cf14baee44d872d58d1 Mon Sep 17 00:00:00 2001 From: Doan Tran Cong Danh Date: Sun, 12 May 2019 10:32:37 +0700 Subject: [PATCH] vsed: reduce number of digest cmd call For a vsed call to `nf' files and `nr' regex, the old code will make `2 * nf * nr' digest calls. the new code will make `nf * (nr + 1)' digest calls. Refereance: https://github.com/void-linux/void-packages/issues/11238 --- common/environment/setup/vsed.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/common/environment/setup/vsed.sh b/common/environment/setup/vsed.sh index ff59bdacb3c..092253696cd 100644 --- a/common/environment/setup/vsed.sh +++ b/common/environment/setup/vsed.sh @@ -44,11 +44,11 @@ vsed() { return 1 fi - for rx in "${regexes[@]}"; do - for f in "${files[@]}"; do - olddigest="$($XBPS_DIGEST_CMD "$f")" - olddigest="${olddigest%% *}" + for f in "${files[@]}"; do + olddigest="$($XBPS_DIGEST_CMD "$f")" + olddigest="${olddigest%% *}" + for rx in "${regexes[@]}"; do sed -i "$f" -e "$rx" || { msg_red "$pkgver: vsed: sed call failed with regex \"$rx\" on file \"$f\"\n" return 1 @@ -60,6 +60,7 @@ vsed() { if [ "$olddigest" = "$newdigest" ]; then msg_warn "$pkgver: vsed: regex \"$rx\" didn't change file \"$f\"\n" fi + olddigest="${newdigest}" done done }