git.iko.soy/typeable/nixpkgs
on master help sign in
Issue 8152 - Reduce number of attribute set created by replaceChars.
commitbe65ac7c32e3d23ecc5964f11cc8e3c658128ec3 authorNicolas B. Pierron <nicolas.b.pierron@gmail.com> dateMon 13 Jul 2015, 23:46 (11 years ago) parent74f4b0d
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