lib/attrset: optimize element access in recursiveUpdateUntil
- Eta reduce formal arguments of `recursiveUpdate'. - Access elements in `recursiveUpdateUntil` using `elemAt` and `head` directly instead of `head (tail xs)` which copies a singleton unnecessarily. (`elemAt` is used instead of `last` to save a primitive call to `length`, this is possible because the 2-tuple structure is guranteed) - Use `length` instead of comparison to empty list to save a copy.
This commit is contained in:
parent
410c054ad3
commit
a54f2231c9
@ -369,7 +369,7 @@ rec {
|
|||||||
value = f name (catAttrs name sets);
|
value = f name (catAttrs name sets);
|
||||||
}) names);
|
}) names);
|
||||||
|
|
||||||
/* Implementation note: Common names appear multiple times in the list of
|
/* Implementation note: Common names appear multiple times in the list of
|
||||||
names, hopefully this does not affect the system because the maximal
|
names, hopefully this does not affect the system because the maximal
|
||||||
laziness avoid computing twice the same expression and listToAttrs does
|
laziness avoid computing twice the same expression and listToAttrs does
|
||||||
not care about duplicated attribute names.
|
not care about duplicated attribute names.
|
||||||
@ -419,8 +419,8 @@ rec {
|
|||||||
let f = attrPath:
|
let f = attrPath:
|
||||||
zipAttrsWith (n: values:
|
zipAttrsWith (n: values:
|
||||||
let here = attrPath ++ [n]; in
|
let here = attrPath ++ [n]; in
|
||||||
if tail values == []
|
if length values == 1
|
||||||
|| pred here (head (tail values)) (head values) then
|
|| pred here (elemAt values 1) (head values) then
|
||||||
head values
|
head values
|
||||||
else
|
else
|
||||||
f here values
|
f here values
|
||||||
@ -446,10 +446,7 @@ rec {
|
|||||||
}
|
}
|
||||||
|
|
||||||
*/
|
*/
|
||||||
recursiveUpdate = lhs: rhs:
|
recursiveUpdate = recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs));
|
||||||
recursiveUpdateUntil (path: lhs: rhs:
|
|
||||||
!(isAttrs lhs && isAttrs rhs)
|
|
||||||
) lhs rhs;
|
|
||||||
|
|
||||||
/* Returns true if the pattern is contained in the set. False otherwise.
|
/* Returns true if the pattern is contained in the set. False otherwise.
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user