mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-15 10:46:15 +02:00
a382919d7d
The primop `builtins.replaceStrings` currently always strictly evaluates the replacement strings, however time and space are wasted for their computation if the corresponding pattern do not occur in the input string. This commit makes the evaluation of the replacement strings lazy by deferring their evaluation to when the corresponding pattern are matched and memoize the result for efficient retrieval on subsequent matches. The testcases for replaceStrings was updated to check for lazy evaluation of the replacements. A note was also added in the release notes to document the behavior change.
12 lines
412 B
Nix
12 lines
412 B
Nix
with builtins;
|
|
|
|
[ (replaceStrings ["o"] ["a"] "foobar")
|
|
(replaceStrings ["o"] [""] "foobar")
|
|
(replaceStrings ["oo"] ["u"] "foobar")
|
|
(replaceStrings ["oo" "a"] ["a" "oo"] "foobar")
|
|
(replaceStrings ["oo" "oo"] ["u" "i"] "foobar")
|
|
(replaceStrings [""] ["X"] "abc")
|
|
(replaceStrings [""] ["X"] "")
|
|
(replaceStrings ["-"] ["_"] "a-b")
|
|
(replaceStrings ["oo" "XX"] ["u" (throw "unreachable")] "foobar")
|
|
]
|