rc.subr: Implement list_vars without using 'read'
'read' pessimistically read(2)s one byte at a time, which can be quite silly for large environments in slow emulators. In my boring user environment, truss shows that the number of read() syscalls to source rc.subr and invoke list_vars is reduced by something like 3400 to 60. ministat(1) shows a significant time difference of about -71% for my environment. Suggested by: jilles Discussed with: dteske, jhb, jilles Differential Revision: https://reviews.freebsd.org/D18481
This commit is contained in:
parent
c1745bf503
commit
b2b1708d59
@ -58,17 +58,29 @@ JID=0
|
||||
# ---------
|
||||
|
||||
# list_vars pattern
|
||||
# List vars matching pattern.
|
||||
# List variables matching glob pattern.
|
||||
#
|
||||
list_vars()
|
||||
{
|
||||
set | { while read LINE; do
|
||||
var="${LINE%%=*}"
|
||||
case "$var" in
|
||||
"$LINE"|*[!a-zA-Z0-9_]*) continue ;;
|
||||
$1) echo $var
|
||||
# Localize 'set' option below.
|
||||
local -
|
||||
local IFS=$'\n' line varname
|
||||
|
||||
# Disable path expansion in unquoted 'for' parameters below.
|
||||
set -o noglob
|
||||
|
||||
for line in $(set); do
|
||||
varname="${line%%=*}"
|
||||
|
||||
case "$varname" in
|
||||
"$line"|*[!a-zA-Z0-9_]*)
|
||||
continue
|
||||
;;
|
||||
$1)
|
||||
echo $varname
|
||||
;;
|
||||
esac
|
||||
done; }
|
||||
done
|
||||
}
|
||||
|
||||
# set_rcvar [var] [defval] [desc]
|
||||
|
Loading…
x
Reference in New Issue
Block a user