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:
Thomas Tuegel 2022-01-08 16:09:57 -06:00
parent c3805ba16c
commit 194b23e6db
No known key found for this signature in database
GPG key ID: 22CBF5249D4B4D59

View file

@ -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" ]