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
This commit is contained in:
Doan Tran Cong Danh 2019-05-12 10:32:37 +07:00 committed by Enno Boland
parent 9374b6938e
commit bbce69f036

View file

@ -44,11 +44,11 @@ vsed() {
return 1 return 1
fi fi
for rx in "${regexes[@]}"; do
for f in "${files[@]}"; do for f in "${files[@]}"; do
olddigest="$($XBPS_DIGEST_CMD "$f")" olddigest="$($XBPS_DIGEST_CMD "$f")"
olddigest="${olddigest%% *}" olddigest="${olddigest%% *}"
for rx in "${regexes[@]}"; do
sed -i "$f" -e "$rx" || { sed -i "$f" -e "$rx" || {
msg_red "$pkgver: vsed: sed call failed with regex \"$rx\" on file \"$f\"\n" msg_red "$pkgver: vsed: sed call failed with regex \"$rx\" on file \"$f\"\n"
return 1 return 1
@ -60,6 +60,7 @@ vsed() {
if [ "$olddigest" = "$newdigest" ]; then if [ "$olddigest" = "$newdigest" ]; then
msg_warn "$pkgver: vsed: regex \"$rx\" didn't change file \"$f\"\n" msg_warn "$pkgver: vsed: regex \"$rx\" didn't change file \"$f\"\n"
fi fi
olddigest="${newdigest}"
done done
done done
} }