From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id BF5451581C1 for ; Mon, 8 Jul 2024 02:31:21 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 9269D2BC018; Mon, 8 Jul 2024 02:31:20 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 7531A2BC018 for ; Mon, 8 Jul 2024 02:31:20 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 6134D342FF7 for ; Mon, 8 Jul 2024 02:31:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 859CE1DF1 for ; Mon, 8 Jul 2024 02:31:17 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1720404268.d639ef781b644478213025450c26fe802cee2a7e.sam@gentoo> Subject: [gentoo-commits] proj/gentoo-functions:master commit in: / X-VCS-Repository: proj/gentoo-functions X-VCS-Files: functions.sh X-VCS-Directories: / X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: d639ef781b644478213025450c26fe802cee2a7e X-VCS-Branch: master Date: Mon, 8 Jul 2024 02:31:17 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: ed3d2cf4-3c3f-4c6f-a3d5-c6f7760556b2 X-Archives-Hash: 1839359e4d996e5a8df81091bbc70d2d commit: d639ef781b644478213025450c26fe802cee2a7e Author: Kerin Millar plushkava net> AuthorDate: Mon Jul 8 02:03:12 2024 +0000 Commit: Sam James gentoo 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 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