mirror of
https://github.com/ilyakooo0/nixpkgs.git
synced 2025-01-01 00:12:39 +03:00
Speed up parsing @args.rsp compiler arguments
Improves upon #25205 https://gist.github.com/pbogdan/9d6986bf931b58a70d75e14eb40ee8a1 parsing time is reduced from one minute to one second
This commit is contained in:
parent
04d4d14d6d
commit
5413bfa8e3
@ -28,17 +28,16 @@ badPath() {
|
|||||||
# States: 0 - outside, 1/2 - unquoted arg/slash, 3/4 - 'arg'/slash, 5/6 - "arg"/slash.
|
# States: 0 - outside, 1/2 - unquoted arg/slash, 3/4 - 'arg'/slash, 5/6 - "arg"/slash.
|
||||||
# State transitions:
|
# State transitions:
|
||||||
rspT=(01235 01235 11111 33413 33333 55651 55555)
|
rspT=(01235 01235 11111 33413 33333 55651 55555)
|
||||||
# Push char on transition:
|
# Push (a) arg or (c) char on transition:
|
||||||
rspC[01]=1 rspC[11]=1 rspC[21]=1 rspC[33]=1 rspC[43]=1 rspC[55]=1 rspC[65]=1
|
rspP[10]=a rspP[01]=c rspP[11]=c rspP[21]=c rspP[33]=c rspP[43]=c rspP[55]=c rspP[65]=c
|
||||||
|
|
||||||
rspParse() {
|
rspParse() {
|
||||||
rsp=()
|
rsp=()
|
||||||
local s="$1"
|
|
||||||
local state=0
|
local state=0
|
||||||
local arg=''
|
local arg=''
|
||||||
|
local c
|
||||||
|
|
||||||
for (( i=0; i<${#s}; i++ )); do
|
while read -r -N1 c; do
|
||||||
local c="${s:$i:1}"
|
|
||||||
local cls=1
|
local cls=1
|
||||||
case "$c" in
|
case "$c" in
|
||||||
' ' | $'\t' | $'\r' | $'\n') cls=0 ;;
|
' ' | $'\t' | $'\r' | $'\n') cls=0 ;;
|
||||||
@ -48,12 +47,10 @@ rspParse() {
|
|||||||
esac
|
esac
|
||||||
local nextstates="${rspT[$state]}"
|
local nextstates="${rspT[$state]}"
|
||||||
local nextstate="${nextstates:$cls:1}"
|
local nextstate="${nextstates:$cls:1}"
|
||||||
if [ "${rspC[$state$nextstate]}" ]; then
|
case "${rspP[$state$nextstate]}" in
|
||||||
arg+="$c"
|
'c') arg+="$c" ;;
|
||||||
elif [ "$state$nextstate" = "10" ]; then
|
'a') rsp+=("$arg"); arg='' ;;
|
||||||
rsp+=("$arg")
|
esac
|
||||||
arg=''
|
|
||||||
fi
|
|
||||||
state="$nextstate"
|
state="$nextstate"
|
||||||
done
|
done
|
||||||
|
|
||||||
@ -68,7 +65,7 @@ expandResponseParams() {
|
|||||||
local p="$1"
|
local p="$1"
|
||||||
shift
|
shift
|
||||||
if [ "${p:0:1}" = '@' -a -e "${p:1}" ]; then
|
if [ "${p:0:1}" = '@' -a -e "${p:1}" ]; then
|
||||||
rspParse "$(<"${p:1}")"
|
rspParse <"${p:1}"
|
||||||
set -- "${rsp[@]}" "$@"
|
set -- "${rsp[@]}" "$@"
|
||||||
else
|
else
|
||||||
params+=("$p")
|
params+=("$p")
|
||||||
|
Loading…
Reference in New Issue
Block a user