diff options
| author | Johannes Kirschbauer <hsjobeki@gmail.com> | 2024-12-02 16:39:29 +0100 |
|---|---|---|
| committer | Johannes Kirschbauer <hsjobeki@gmail.com> | 2024-12-03 10:03:19 +0100 |
| commit | 58c115499f8c395d151ba9dba4a18c7734650649 (patch) | |
| tree | 1734b6c84e64f7f5cfe9489ed1d641315c956240 /lib/types.nix | |
| parent | lib/types: standardise attrsOf functor.wrapped warning and add a test (diff) | |
| download | nixpkgs-58c115499f8c395d151ba9dba4a18c7734650649.tar.gz | |
lib.types: improve performance on attrsWith
Diffstat (limited to 'lib/types.nix')
| -rw-r--r-- | lib/types.nix | 42 |
1 files changed, 21 insertions, 21 deletions
diff --git a/lib/types.nix b/lib/types.nix index caa7b6e7b5f2..dd1e8ab9d016 100644 --- a/lib/types.nix +++ b/lib/types.nix @@ -597,17 +597,31 @@ rec { # base type for lazyAttrsOf and attrsOf attrsWith = - { - elemType, - lazy ? false, - }: let - typeName = if lazy then "lazyAttrsOf" else "attrsOf"; # Push down position info. pushPositions = map (def: mapAttrs (n: v: { inherit (def) file; value = v; }) def.value); + binOp = lhs: rhs: + let + elemType = lhs.elemType.typeMerge rhs.elemType.functor; + lazy = + if lhs.lazy == rhs.lazy then + lhs.lazy + else + null; + in + if elemType == null || lazy == null then + null + else + { + inherit elemType lazy; + }; in + { + elemType, + lazy ? false, + }: mkOptionType { - name = typeName; + name = if lazy then "lazyAttrsOf" else "attrsOf"; description = (if lazy then "lazy attribute set" else "attribute set") + " of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}"; descriptionClass = "composite"; check = isAttrs; @@ -642,21 +656,7 @@ rec { # Important!: Add new function attributes here in case of future changes inherit elemType lazy; }; - binOp = lhs: rhs: - let - elemType = lhs.elemType.typeMerge rhs.elemType.functor; - lazy = - if lhs.lazy == rhs.lazy then - lhs.lazy - else - null; - in - if elemType == null || lazy == null then - null - else - { - inherit elemType lazy; - }; + inherit binOp; }; nestedTypes.elemType = elemType; }; |
