From 194b23e6db7a8b94cc5d9df4ef84c1083fc91090 Mon Sep 17 00:00:00 2001 From: Thomas Tuegel Date: Sat, 8 Jan 2022 16:09:57 -0600 Subject: [PATCH] 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. --- .../extra-cmake-modules/setup-hook.sh | 27 ++++++++++--------- 1 file 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" ]