configure: speed up flatten_extralibs_wrapper()

x50 - x200 faster.

Currently configure spends 50-70% of its runtime inside a single
function: flatten_extralibs[_wrapper] - which does string processing.

During its run, nearly 20K command substitutions (subshells) are used,
including its callees unique() and resolve(), which is the reason
for its lengthy run.

This commit avoids all subshells during its execution, speeding it up
by about two orders of magnitude, and reducing the overall configure
runtime by 50-70% .

resolve() is rewritten to avoid subshells, and in unique() and
flatten_extralibs() we "inline" the filter[_out] functionality.

Note that logically, "unique" functionality has more than one possible
output (depending on which of the recurring items is kept). As it
turns out, other parts expect the last recurring item to be kept
(which was the original behavior of uniqie()). This patch preservs
its output order.

Tested-by: Michael Niedermayer <michael@niedermayer.cc>
Tested-by: Helmut K. C. Tessarek <tessarek@evermeet.cx>
Tested-by: Dave Yeo <daveryeo@telus.net>
Tested-by: Reino Wijnsma <rwijnsma@xs4all.nl>
Signed-off-by: James Almer <jamrial@gmail.com>
(cherry picked from commit 58b81ac621)
This commit is contained in:
Avi Halachmi (:avih) 2018-07-30 22:39:15 +03:00 committed by James Almer
parent eb495b20e5
commit 42355d12db
1 changed files with 33 additions and 13 deletions

46
configure vendored
View File

@ -836,22 +836,37 @@ prepend(){
eval "$var=\"$* \$$var\"" eval "$var=\"$* \$$var\""
} }
reverse () {
eval '
reverse_out=
for v in $'$1'; do
reverse_out="$v $reverse_out"
done
'$1'=$reverse_out
'
}
# keeps the last occurence of each non-unique item
unique(){ unique(){
var=$1 unique_out=
uniq_list="" eval unique_in=\$$1
for tok in $(eval echo \$$var); do reverse unique_in
uniq_list="$(filter_out $tok $uniq_list) $tok" for v in $unique_in; do
# " $unique_out" +space such that every item is surrounded with spaces
case " $unique_out" in *" $v "*) continue; esac # already in list
unique_out="$unique_out$v "
done done
eval "$var=\"${uniq_list}\"" reverse unique_out
eval $1=\$unique_out
} }
resolve(){ resolve(){
var=$1 resolve_out=
tmpvar= eval resolve_in=\$$1
for entry in $(eval echo \$$var); do for v in $resolve_in; do
tmpvar="$tmpvar $(eval echo \$${entry})" eval 'resolve_out="$resolve_out$'$v' "'
done done
eval "$var=\"${tmpvar}\"" eval $1=\$resolve_out
} }
add_cppflags(){ add_cppflags(){
@ -6682,14 +6697,19 @@ if test $target_os = "haiku"; then
fi fi
flatten_extralibs(){ flatten_extralibs(){
unset nested_entries nested_entries=
list_name=$1 list_name=$1
eval list=\$${1} eval list=\$${1}
for entry in $list; do for entry in $list; do
entry_copy=$entry entry_copy=$entry
resolve entry_copy resolve entry_copy
append nested_entries $(filter '*_extralibs' $entry_copy) flat_entries=
flat_entries=$(filter_out '*_extralibs' $entry_copy) for e in $entry_copy; do
case $e in
*_extralibs) nested_entries="$nested_entries$e ";;
*) flat_entries="$flat_entries$e ";;
esac
done
eval $entry="\$flat_entries" eval $entry="\$flat_entries"
done done
append $list_name "$nested_entries" append $list_name "$nested_entries"