mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib.types: improve performance on attrsWith
This commit is contained in:
parent
e60e2e6916
commit
58c115499f
1 changed files with 21 additions and 21 deletions
|
@ -597,17 +597,31 @@ rec {
|
||||||
|
|
||||||
# base type for lazyAttrsOf and attrsOf
|
# base type for lazyAttrsOf and attrsOf
|
||||||
attrsWith =
|
attrsWith =
|
||||||
|
let
|
||||||
|
# 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,
|
elemType,
|
||||||
lazy ? false,
|
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);
|
|
||||||
in
|
|
||||||
mkOptionType {
|
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}";
|
description = (if lazy then "lazy attribute set" else "attribute set") + " of ${optionDescriptionPhrase (class: class == "noun" || class == "composite") elemType}";
|
||||||
descriptionClass = "composite";
|
descriptionClass = "composite";
|
||||||
check = isAttrs;
|
check = isAttrs;
|
||||||
|
@ -642,21 +656,7 @@ rec {
|
||||||
# Important!: Add new function attributes here in case of future changes
|
# Important!: Add new function attributes here in case of future changes
|
||||||
inherit elemType lazy;
|
inherit elemType lazy;
|
||||||
};
|
};
|
||||||
binOp = lhs: rhs:
|
inherit binOp;
|
||||||
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;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
nestedTypes.elemType = elemType;
|
nestedTypes.elemType = elemType;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue