Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/atf/dist/atf-sh Replace a pipe into tr to norma...



details:   https://anonhg.NetBSD.org/src/rev/2832273e69e9
branches:  trunk
changeset: 954772:2832273e69e9
user:      kre <kre%NetBSD.org@localhost>
date:      Thu Sep 10 22:51:10 2020 +0000

description:
Replace a pipe into tr to normalise a var name (convert '.' or '-'
into '_' to meet sh variable name rules) into a shell string processing
loop.

On my test system, this reduces the total elapsed time for the bin/sh ATF
tests from about 109 secs to about 102 (user cpu from 24.5 to 21, sys cpu
from 34 to 30) and the usr.bin/make tests elapsed time from 42.5 to 40
secs (user from a bit over 15 to a bit over 13, and sys from 16+ to 13+).
(Recorded on an AMD64 domU).

These probably exaggerate the effect, as there are a bunch of quite small
tests, which means the ATF overhead (which this change affects) is a greater
proportion of the total test time than for some other tests where most of
the time is spent actually testing.

But I am fairly confident that there will be at least some improvement.

This could be further improved by removing the cmdsub invocation method,
and instead passing the name of a variable containing the string to
normalise (with the result returned in that same var) - but that would
mean altering all the callers as well.   Some other time maybe.

diffstat:

 external/bsd/atf/dist/atf-sh/libatf-sh.subr |  10 +++++++++-
 1 files changed, 9 insertions(+), 1 deletions(-)

diffs (20 lines):

diff -r 3580f4c88d85 -r 2832273e69e9 external/bsd/atf/dist/atf-sh/libatf-sh.subr
--- a/external/bsd/atf/dist/atf-sh/libatf-sh.subr       Thu Sep 10 22:47:22 2020 +0000
+++ b/external/bsd/atf/dist/atf-sh/libatf-sh.subr       Thu Sep 10 22:51:10 2020 +0000
@@ -544,7 +544,15 @@
 #
 _atf_normalize()
 {
-    echo ${1} | tr .- __
+    while :
+    do
+       case "${1}" in
+       (*.*)   set -- "${1%.*}_${1##*.}";;
+       (*-*)   set -- "${1%-*}_${1##*-}";;
+       (*)     break;;
+       esac
+    done
+    printf "%s\n" "$1"
 }
 
 #



Home | Main Index | Thread Index | Old Index