diff options
author | EuAndreh <eu@euandre.org> | 2024-10-12 14:58:06 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2024-10-12 15:37:59 -0300 |
commit | 45d6c999cc5852cd59f23f250fcf3672232038a3 (patch) | |
tree | 9c776e0070bd5d03820648203fb6ee2975860561 /bin | |
parent | etc/guix/home.scm: Add mpv package (diff) | |
download | dotfiles-45d6c999cc5852cd59f23f250fcf3672232038a3.tar.gz dotfiles-45d6c999cc5852cd59f23f250fcf3672232038a3.tar.xz |
bin/muffle: Speed up
First, use sort -m, as both inputs are already sorted. This both
changes from it from O(n*log(n)) to O(n), and allows sort(1) to produce
streaming output, instead of sponging all the input, and potentially
spilling to disk during the process.
Second, use awk(1) when looping. Not only awk(1) is made for this type
of job, but also we only call it once and let it do the loop, over
looping manually and calling '['(1), printf() and cut(1) on each
iteration. Now we call cut(1) only once.
It went from being annoying enough to make me pause considering using to
being unnoticeable.
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/muffle | 15 |
1 files changed, 5 insertions, 10 deletions
@@ -81,18 +81,13 @@ timed() { echo 0 > "$STATUS_F" { - { "$@" || echo $? > "$STATUS_F"; } | timed | pre out > "$OUT" -} 2>&1 | timed | pre err > "$ERR" + { "$@" || echo $? > "$STATUS_F"; } | pre -n out | timed > "$OUT" +} 2>&1 | pre -n err | timed > "$ERR" STATUS="$(cat "$STATUS_F")" if [ "$INVERT" = false -a "$STATUS" != 0 ] || [ "$INVERT" = true -a "$STATUS" = 0 ]; then - cat "$OUT" "$ERR" | - sort -k2 | while read -r line; do - if [ "$(printf '%s\n' "$line" | cut -d' ' -f1)" = 'out:' ]; then - printf '%s\n' "$line" | cut -d' ' -f3- >&1 - else - printf '%s\n' "$line" | cut -d' ' -f3- >&2 - fi - done + sort -m "$OUT" "$ERR" | cut -d' ' -f2- | awk '{ + print substr($0, length($1) + 2) > "/dev/std" $1 + }' exit "$STATUS" fi |