diff options
author | 2024-07-08 03:03:12 +0100 | |
---|---|---|
committer | 2024-07-08 03:04:28 +0100 | |
commit | d639ef781b644478213025450c26fe802cee2a7e (patch) | |
tree | e73b7a72adb724f761fe6f5a7444a342014f925f | |
parent | Correct the implementation of contains_all() (diff) | |
download | gentoo-functions-d639ef781b644478213025450c26fe802cee2a7e.tar.gz gentoo-functions-d639ef781b644478213025450c26fe802cee2a7e.tar.bz2 gentoo-functions-d639ef781b644478213025450c26fe802cee2a7e.zip |
Have _update_time() use a faster rounding method for sh
Directly implement a round half up algorithm for sh, thereby avoiding a
command substitution and a potential subshell along with it.
Signed-off-by: Kerin Millar <kfm@plushkava.net>
-rw-r--r-- | functions.sh | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/functions.sh b/functions.sh index ccd0d1d..1295a2b 100644 --- a/functions.sh +++ b/functions.sh @@ -755,16 +755,18 @@ _update_time() elif [ -f /proc/uptime ]; then _update_time() { - local ds s timeval + local cs ds s timeval IFS=' ' read -r timeval _ < /proc/uptime || return s=${timeval%.*} - ds=$(printf '%.1f' ".${timeval#*.}") - if [ "${ds}" = "1.0" ]; then - ds=10 - else - ds=${ds#0.} - fi + cs=${timeval#*.} + case ${cs} in + ?[0-4]) + ds=${cs%?} + ;; + ?[5-9]) + ds=$(( ${cs%?} + 1 )) + esac genfun_time=$(( s * 10 + ds )) } else |