mirror of
https://github.com/NixOS/nix
synced 2025-07-07 14:21:48 +02:00
add zipAttrsWith primop
nixpkgs can save a good bit of eval memory with this primop. zipAttrsWith is used quite a bit around nixpkgs (eg in the form of recursiveUpdate), but the most costly application for this primop is in the module system. it improves the implementation of zipAttrsWith from nixpkgs by not checking an attribute multiple times if it occurs more than once in the input list, allocates less values and set elements, and just avoids many a temporary object in general. nixpkgs has a more generic version of this operation, zipAttrsWithNames, but this version is only used once so isn't suitable for being the base of a new primop. if it were to be used more we should add a second primop instead.
This commit is contained in:
parent
96d08fcd66
commit
00c993f48b
4 changed files with 96 additions and 0 deletions
1
tests/lang/eval-okay-zipAttrsWith.exp
Normal file
1
tests/lang/eval-okay-zipAttrsWith.exp
Normal file
|
@ -0,0 +1 @@
|
|||
{ "0" = { n = "0"; v = [ 5 23 29 ]; }; "1" = { n = "1"; v = [ 7 30 ]; }; "2" = { n = "2"; v = [ 18 ]; }; "4" = { n = "4"; v = [ 10 ]; }; "5" = { n = "5"; v = [ 15 25 26 31 ]; }; "6" = { n = "6"; v = [ 3 14 ]; }; "7" = { n = "7"; v = [ 12 ]; }; "8" = { n = "8"; v = [ 2 6 8 9 ]; }; "9" = { n = "9"; v = [ 0 16 ]; }; a = { n = "a"; v = [ 17 21 22 27 ]; }; c = { n = "c"; v = [ 11 24 ]; }; d = { n = "d"; v = [ 4 13 28 ]; }; e = { n = "e"; v = [ 20 ]; }; f = { n = "f"; v = [ 1 19 ]; }; }
|
9
tests/lang/eval-okay-zipAttrsWith.nix
Normal file
9
tests/lang/eval-okay-zipAttrsWith.nix
Normal file
|
@ -0,0 +1,9 @@
|
|||
with import ./lib.nix;
|
||||
|
||||
let
|
||||
str = builtins.hashString "sha256" "test";
|
||||
in
|
||||
builtins.zipAttrsWith
|
||||
(n: v: { inherit n v; })
|
||||
(map (n: { ${builtins.substring n 1 str} = n; })
|
||||
(range 0 31))
|
Loading…
Add table
Add a link
Reference in a new issue