git.iko.soy/typeable/nixpkgs
on master help sign in
Merge pull request #8806 from nbp/issue-8152

Issue 8152 - Reduce number of attribute sets created by replaceChars.

commitff8b35a6431b4fad09cc98e65388ea66be3535b0 authorNicolas B. Pierron <nicolas.b.pierron@gmail.com> dateTue 14 Jul 2015, 12:34 (11 years ago) parent7e2082cbe65ac7
1 file changed+6−4
lib/strings.nix+6−4
lib/strings.nix+6−4
@@ -107,11 +107,13 @@ rec {
107107 # replaceChars ["<" ">"] ["&lt;" "&gt;"] "<foo>" returns "&lt;foo&gt;".
108108 replaceChars = del: new: s:
109109 let
110+ substList = lib.zipLists del new;
110111 subst = c:
111− (lib.fold
112− (sub: res: if sub.fst == c then sub else res)
113− {fst = c; snd = c;} (lib.zipLists del new)
114− ).snd;
112+ let found = lib.findFirst (sub: sub.fst == c) null substList; in
113+ if found == null then
114+ c
115+ else
116+ found.snd;
115117 in
116118 stringAsChars subst s;
117119