commit:     f426bf67aaaac78938aff33f6cc018fdcf7c3466
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Aug  2 10:14:03 2024 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> 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 <kfm <AT> 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

Reply via email to