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.

+14 -13
+14 -13
pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh
··· 59 59 "wallpapers" "applications" "desktop-directories" "mime" "appdata" "dbus-1" \ 60 60 ) 61 61 62 - ecmHostPathSeen=( ) 62 + # ecmHostPathsSeen is an associative array of the paths that have already been 63 + # seen by ecmHostPathHook. 64 + declare -gA ecmHostPathsSeen 63 65 64 - ecmUnseenHostPath() { 65 - for pkg in "${ecmHostPathSeen[@]}" 66 - do 67 - if [ "${pkg:?}" == "$1" ] 68 - then 69 - return 1 70 - fi 71 - done 72 - 73 - ecmHostPathSeen+=("$1") 74 - return 0 66 + ecmHostPathIsNotSeen() { 67 + if [[ -n "${ecmHostPathsSeen["$1"]:-}" ]]; then 68 + # The path has been seen before. 69 + return 1 70 + else 71 + # The path has not been seen before. 72 + # Now it is seen, so record it. 73 + ecmHostPathsSeen["$1"]=1 74 + return 0 75 + fi 75 76 } 76 77 77 78 ecmHostPathHook() { 78 - ecmUnseenHostPath "$1" || return 0 79 + ecmHostPathIsNotSeen "$1" || return 0 79 80 80 81 local xdgConfigDir="$1/etc/xdg" 81 82 if [ -d "$xdgConfigDir" ]