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 BBB72159C9B for ; 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 13359E2A69; 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 EE4BEE2A67 for ; 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 73826343026 for ; Fri, 2 Aug 2024 23:14:16 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id CF91B1EA9 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: <1722619876.81d81d22d039f3ed966df31c61d8ef5b664f1c4d.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: 81d81d22d039f3ed966df31c61d8ef5b664f1c4d 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: 14cce6be-68ba-4863-9aec-e333e09bd2cb X-Archives-Hash: 36aabd7d972215052e6c816013190bac commit: 81d81d22d039f3ed966df31c61d8ef5b664f1c4d Author: Kerin Millar plushkava net> AuthorDate: Fri Aug 2 17:31:16 2024 +0000 Commit: Sam James gentoo org> CommitDate: Fri Aug 2 17:31:16 2024 +0000 URL: https://gitweb.gentoo.org/proj/gentoo-functions.git/commit/?id=81d81d22 Jettison the bash-specific hr() implementation Testing the BASH variable for non-emptiness is an inadequate pretext for activating the bash-optimised code path. Instead, the test would have to be implemented like so ... if ! case ${BASH_COMPAT} in 3?|4[012]) false ;; esac && _has_bash 4 3 then ... fi Given that hr() is not expected to be called often, and that the sh code was already improved by employing a divide-by-8 strategy, I don't consider it to be worth the trouble. Signed-off-by: Kerin Millar plushkava.net> functions.sh | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/functions.sh b/functions.sh index 5ef96ae..b7e6c1d 100644 --- a/functions.sh +++ b/functions.sh @@ -175,21 +175,15 @@ hr() fi char=${1--} char=${char%"${char#?}"} - if [ "${BASH}" ]; then - # shellcheck disable=3045 - printf -v hr '%*s' "${length}" '' - 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 - printf '%s\n' "${hr}" - fi + 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 + printf '%s\n' "${hr}" } #