summary refs log tree commit diff
path: root/lib/attrsets.nix
diff options
context:
space:
mode:
authorpolykernel <81340136+polykernel@users.noreply.github.com>2021-12-27 17:16:14 -0500
committerpolykernel <81340136+polykernel@users.noreply.github.com>2021-12-27 18:17:52 -0500
commita54f2231c9c4ea9e456511e855df11fe7df5ba71 (patch)
tree64f6b3eef837d9716addede8ea7fd648514237ad /lib/attrsets.nix
parent410c054ad3441e06da54384695637ba2886fbbca (diff)
downloadnixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar.gz
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar.bz2
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar.lz
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar.xz
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.tar.zst
nixpkgs-a54f2231c9c4ea9e456511e855df11fe7df5ba71.zip
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.
Diffstat (limited to 'lib/attrsets.nix')
-rw-r--r--lib/attrsets.nix11
1 files changed, 4 insertions, 7 deletions
diff --git a/lib/attrsets.nix b/lib/attrsets.nix
index 812521ce6d1..4e88601dbd3 100644
--- a/lib/attrsets.nix
+++ b/lib/attrsets.nix
@@ -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.