summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Tuegel <ttuegel@mailbox.org>2022-01-08 16:09:57 -0600
committerThomas Tuegel <ttuegel@mailbox.org>2022-01-17 12:28:16 -0600
commit194b23e6db7a8b94cc5d9df4ef84c1083fc91090 (patch)
tree8b1b4694855053d3abe78270cdc90978e337c860
parentc3805ba16cf4a060cdbb82d4ce21b74f9989dbb8 (diff)
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.
-rw-r--r--pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh27
1 files changed, 14 insertions, 13 deletions
diff --git a/pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh b/pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh
index 4135f6bfd7aa..ac077b73d6a6 100644
--- a/pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh
+++ b/pkgs/development/libraries/kde-frameworks/extra-cmake-modules/setup-hook.sh
@@ -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" ]