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:
polykernel 2021-12-27 17:16:14 -05:00
parent 410c054ad3
commit a54f2231c9

View File

@ -369,7 +369,7 @@ rec {
value = f name (catAttrs name sets);
}) 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
laziness avoid computing twice the same expression and listToAttrs does
not care about duplicated attribute names.
@ -419,8 +419,8 @@ rec {
let f = attrPath:
zipAttrsWith (n: values:
let here = attrPath ++ [n]; in
if tail values == []
|| pred here (head (tail values)) (head values) then
if length values == 1
|| pred here (elemAt values 1) (head values) then
head values
else
f here values
@ -446,10 +446,7 @@ rec {
}
*/
recursiveUpdate = lhs: rhs:
recursiveUpdateUntil (path: lhs: rhs:
!(isAttrs lhs && isAttrs rhs)
) lhs rhs;
recursiveUpdate = recursiveUpdateUntil (path: lhs: rhs: !(isAttrs lhs && isAttrs rhs));
/* Returns true if the pattern is contained in the set. False otherwise.