From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <gentoo-commits+bounces-1658327-garchives=archives.gentoo.org@lists.gentoo.org>
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 672B5159C9B
	for <garchives@archives.gentoo.org>; Fri,  2 Aug 2024 23:14:20 +0000 (UTC)
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id 134D6E2A6C;
	Fri,  2 Aug 2024 23:14:18 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (4096 bits))
	(No client certificate requested)
	by pigeon.gentoo.org (Postfix) with ESMTPS id EF4CBE2A68
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Aug 2024 23:14:17 +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))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id 6DD22343025
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Aug 2024 23:14:16 +0000 (UTC)
Received: from localhost.localdomain (localhost [IPv6:::1])
	by oystercatcher.gentoo.org (Postfix) with ESMTP id E1CC41EAA
	for <gentoo-commits@lists.gentoo.org>; Fri,  2 Aug 2024 23:14:12 +0000 (UTC)
From: "Sam James" <sam@gentoo.org>
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" <sam@gentoo.org>
Message-ID: <1722625100.a9dd85a8a1954ee516fc989a04afd7f43e58ffe8.sam@gentoo>
Subject: [gentoo-commits] proj/gentoo-functions:master commit in: /
X-VCS-Repository: proj/gentoo-functions
X-VCS-Files: functions.sh test-functions
X-VCS-Directories: /
X-VCS-Committer: sam
X-VCS-Committer-Name: Sam James
X-VCS-Revision: a9dd85a8a1954ee516fc989a04afd7f43e58ffe8
X-VCS-Branch: master
Date: Fri,  2 Aug 2024 23:14:12 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
X-Archives-Salt: fb81cda8-7e0d-4d61-8af0-460aa950bb5d
X-Archives-Hash: 0793582a2e473938bc1d39b6d9ab3db0

commit:     a9dd85a8a1954ee516fc989a04afd7f43e58ffe8
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug  2 18:41:50 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Aug  2 18:58:20 2024 +0000
URL:        https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=a9dd85a8

Have hr() employ a divide-by-16 strategy

A factor of 16 was shown to be faster on average by timing how long it
takes for bash to print a rule 5000 times for all lengths between 40 and
132, inclusive.

Factor  Time       StdDev
8       87.004000  3.961607
16      82.893000  3.971257

Further, 16 remains a factor of 80, which is often the number of columns
that a terminal emulator is initialised with.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>

 functions.sh   | 12 ++++++------
 test-functions |  4 ++--
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/functions.sh b/functions.sh
index b7e6c1d..9b6220b 100644
--- a/functions.sh
+++ b/functions.sh
@@ -164,7 +164,7 @@ has_systemd()
 #
 hr()
 {
-	local char hr i length
+	local c hr i length
 
 	if [ "$#" -ge 2 ] && is_int "$2"; then
 		length=$2
@@ -173,15 +173,15 @@ hr()
 	else
 		length=80
 	fi
-	char=${1--}
-	char=${char%"${char#?}"}
+	c=${1--}
+	c=${c%"${c#?}"}
 	i=0
-	while [ "$(( i += 8 ))" -le "${length}" ]; do
-		hr=${hr}${char}${char}${char}${char}${char}${char}${char}${char}
+	while [ "$(( i += 16 ))" -le "${length}" ]; do
+		hr=${hr}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}${c}
 	done
 	i=${#hr}
 	while [ "$(( i += 1 ))" -le "${length}" ]; do
-		hr=${hr}${char}
+		hr=${hr}${c}
 	done
 	printf '%s\n' "${hr}"
 }

diff --git a/test-functions b/test-functions
index 43b5320..2ad76e8 100755
--- a/test-functions
+++ b/test-functions
@@ -514,10 +514,10 @@ test_hr() {
 		eq  0  "$(printf '%80s' | tr ' ' -)"  -    N/A  \
 		eq  0  ''                             -    0    \
 		eq  0  -                              -    1    \
-		eq  0  ---------                      -    9    \
+		eq  0  -----------------              -    17    \
 		eq  0  ''                             xyz  0    \
 		eq  0  x                              xyz  1    \
-		eq  0  xxxxxxxxx                      xyz  9
+		eq  0  xxxxxxxxxxxxxxxxx              xyz  17
 
 	callback() {
 		shift