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 21BB0159C9B for ; Fri, 2 Aug 2024 23:14:18 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D73C7E2A57; Fri, 2 Aug 2024 23:14:15 +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 BC025E2A55 for ; Fri, 2 Aug 2024 23:14:15 +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 1220234300F for ; Fri, 2 Aug 2024 23:14:15 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 8404D1EA5 for ; Fri, 2 Aug 2024 23:14:12 +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: <1722615674.f426bf67aaaac78938aff33f6cc018fdcf7c3466.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: f426bf67aaaac78938aff33f6cc018fdcf7c3466 X-VCS-Branch: master Date: Fri, 2 Aug 2024 23:14:12 +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: 2f3d17e1-2cab-43e7-975c-cb5f0fa46685 X-Archives-Hash: 80af35e1913f05f6d004750bdcc5c657 commit: f426bf67aaaac78938aff33f6cc018fdcf7c3466 Author: Kerin Millar plushkava net> AuthorDate: Fri Aug 2 10:14:03 2024 +0000 Commit: Sam James gentoo org> CommitDate: Fri Aug 2 16:21:14 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=f426bf67 Render hr() faster still for shells other than bash Reduce the number of loop iterations by initially trying to append characters 8 at a time. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 4 ++++ test-functions | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/functions.sh b/functions.sh index b40e17b..a002e54 100644 --- a/functions.sh +++ b/functions.sh @@ -181,6 +181,10 @@ hr() eval 'printf %s\\n "${hr//?/"$char"}"' else i=0 + while [ "$(( i += 8 ))" -le "${length}" ]; do + hr=${hr}${char}${char}${char}${char}${char}${char}${char}${char} + done + i=${#hr} while [ "$(( i += 1 ))" -le "${length}" ]; do hr=${hr}${char} done diff --git a/test-functions b/test-functions index 4b3107f..8070c8d 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 ----- - 5 \ + eq 0 --------- - 9 \ eq 0 '' xyz 0 \ eq 0 x xyz 1 \ - eq 0 xxxxx xyz 5 + eq 0 xxxxxxxxx xyz 9 callback() { shift