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.
This commit is contained in:
kre 2020-09-10 22:51:10 +00:00
parent 2bf492c8b8
commit c2105d446d

View File

@ -544,7 +544,15 @@ _atf_list_tcs()
#
_atf_normalize()
{
echo ${1} | tr .- __
while :
do
case "${1}" in
(*.*) set -- "${1%.*}_${1##*.}";;
(*-*) set -- "${1%-*}_${1##*-}";;
(*) break;;
esac
done
printf "%s\n" "$1"
}
#