extra-cmake-modules: Use associative array to recognize paths
Fixes #99308. Use an associative array to recognize paths that have already been seen by the host path hook. This takes advantage of fast lookup of associative array keys in Bash. The previous solution scanned a linear array, which was accidentally quadratic.
This commit is contained in:
parent
c3805ba16c
commit
194b23e6db
|
@ -59,23 +59,24 @@ xdgDataSubdirs=( \
|
|||
"wallpapers" "applications" "desktop-directories" "mime" "appdata" "dbus-1" \
|
||||
)
|
||||
|
||||
ecmHostPathSeen=( )
|
||||
# ecmHostPathsSeen is an associative array of the paths that have already been
|
||||
# seen by ecmHostPathHook.
|
||||
declare -gA ecmHostPathsSeen
|
||||
|
||||
ecmUnseenHostPath() {
|
||||
for pkg in "${ecmHostPathSeen[@]}"
|
||||
do
|
||||
if [ "${pkg:?}" == "$1" ]
|
||||
then
|
||||
return 1
|
||||
fi
|
||||
done
|
||||
|
||||
ecmHostPathSeen+=("$1")
|
||||
return 0
|
||||
ecmHostPathIsNotSeen() {
|
||||
if [[ -n "${ecmHostPathsSeen["$1"]:-}" ]]; then
|
||||
# The path has been seen before.
|
||||
return 1
|
||||
else
|
||||
# The path has not been seen before.
|
||||
# Now it is seen, so record it.
|
||||
ecmHostPathsSeen["$1"]=1
|
||||
return 0
|
||||
fi
|
||||
}
|
||||
|
||||
ecmHostPathHook() {
|
||||
ecmUnseenHostPath "$1" || return 0
|
||||
ecmHostPathIsNotSeen "$1" || return 0
|
||||
|
||||
local xdgConfigDir="$1/etc/xdg"
|
||||
if [ -d "$xdgConfigDir" ]
|
||||
|
|
Loading…
Reference in a new issue