Commit 1de8e072 authored by Robert Hensing's avatar Robert Hensing
Browse files

lib: refactor `filterAttrs`

`filter` is a primop which is designed for this task, and it saves
the allocation of some singleton lists here.
parent 83e1488c
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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