commit: d639ef781b644478213025450c26fe802cee2a7e
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Jul 8 02:03:12 2024 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Jul 8 02:04:28 2024 +0000
URL:
https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=d639ef78
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 <AT> plushkava.net>
functions.sh | 16 +++++++++-------
1 file 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