diff options
author | Orivej Desh <orivej@gmx.fr> | 2017-06-13 14:10:40 +0000 |
---|---|---|
committer | Orivej Desh <orivej@gmx.fr> | 2017-06-14 18:56:44 +0000 |
commit | 5413bfa8e37d8fe7b3f5a80786d7ac6712e87089 (patch) | |
tree | 5f19477ad69756292951dccf0d9feb7ccde7aec7 /pkgs/build-support | |
parent | 04d4d14d6d1662526a42234f4500f1161cb7936d (diff) | |
download | nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar.gz nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar.bz2 nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar.lz nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar.xz nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.tar.zst nixlib-5413bfa8e37d8fe7b3f5a80786d7ac6712e87089.zip |
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
Diffstat (limited to 'pkgs/build-support')
-rw-r--r-- | pkgs/build-support/cc-wrapper/utils.sh | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/pkgs/build-support/cc-wrapper/utils.sh b/pkgs/build-support/cc-wrapper/utils.sh index d17930e8ab5d..8cefc47816f8 100644 --- a/pkgs/build-support/cc-wrapper/utils.sh +++ b/pkgs/build-support/cc-wrapper/utils.sh @@ -28,17 +28,16 @@ badPath() { # States: 0 - outside, 1/2 - unquoted arg/slash, 3/4 - 'arg'/slash, 5/6 - "arg"/slash. # State transitions: rspT=(01235 01235 11111 33413 33333 55651 55555) -# Push char on transition: -rspC[01]=1 rspC[11]=1 rspC[21]=1 rspC[33]=1 rspC[43]=1 rspC[55]=1 rspC[65]=1 +# Push (a) arg or (c) char on transition: +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() { rsp=() - local s="$1" local state=0 local arg='' + local c - for (( i=0; i<${#s}; i++ )); do - local c="${s:$i:1}" + while read -r -N1 c; do local cls=1 case "$c" in ' ' | $'\t' | $'\r' | $'\n') cls=0 ;; @@ -48,12 +47,10 @@ rspParse() { esac local nextstates="${rspT[$state]}" local nextstate="${nextstates:$cls:1}" - if [ "${rspC[$state$nextstate]}" ]; then - arg+="$c" - elif [ "$state$nextstate" = "10" ]; then - rsp+=("$arg") - arg='' - fi + case "${rspP[$state$nextstate]}" in + 'c') arg+="$c" ;; + 'a') rsp+=("$arg"); arg='' ;; + esac state="$nextstate" done @@ -68,7 +65,7 @@ expandResponseParams() { local p="$1" shift if [ "${p:0:1}" = '@' -a -e "${p:1}" ]; then - rspParse "$(<"${p:1}")" + rspParse <"${p:1}" set -- "${rsp[@]}" "$@" else params+=("$p") |