From 1de8e072168d6be15e722a7f745d25f247c3496a Mon Sep 17 00:00:00 2001 From: Robert Hensing Date: Thu, 31 Oct 2024 16:30:07 +0100 Subject: [PATCH] lib: refactor `filterAttrs` `filter` is a primop which is designed for this task, and it saves the allocation of some singleton lists here. --- lib/attrsets.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 2e8e9a05599a..f4b03e5b53aa 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -7,7 +7,7 @@ let inherit (builtins) head length; inherit (lib.trivial) isInOldestRelease mergeAttrs warn warnIf; inherit (lib.strings) concatStringsSep concatMapStringsSep escapeNixIdentifier sanitizeDerivationName; - inherit (lib.lists) foldr foldl' concatMap elemAt all partition groupBy take foldl; + inherit (lib.lists) filter foldr foldl' concatMap elemAt all partition groupBy take foldl; in rec { @@ -644,7 +644,7 @@ rec { filterAttrs = pred: set: - removeAttrs set (concatMap (name: if pred name set.${name} then [ ] else [ name ]) (attrNames set)); + removeAttrs set (filter (name: ! pred name set.${name}) (attrNames set)); /** Filter an attribute set recursively by removing all attributes for