diff options
author | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2015-07-14 12:34:36 +0200 |
---|---|---|
committer | Nicolas B. Pierron <nicolas.b.pierron@gmail.com> | 2015-07-14 12:34:36 +0200 |
commit | ff8b35a6431b4fad09cc98e65388ea66be3535b0 (patch) | |
tree | d2517ea94dc5b4fb90e4a0ed7ed8e8a9c123c55e /lib | |
parent | 7e2082c16f5ccc709dd9062e63f176fdcdd1badc (diff) | |
parent | be65ac7c32e3d23ecc5964f11cc8e3c658128ec3 (diff) |
Merge pull request #8806 from nbp/issue-8152
Issue 8152 - Reduce number of attribute sets created by replaceChars.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strings.nix | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index 39112407c5708..d9f7f6c2db814 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -107,11 +107,13 @@ rec { # replaceChars ["<" ">"] ["<" ">"] "<foo>" returns "<foo>". replaceChars = del: new: s: let + substList = lib.zipLists del new; subst = c: - (lib.fold - (sub: res: if sub.fst == c then sub else res) - {fst = c; snd = c;} (lib.zipLists del new) - ).snd; + let found = lib.findFirst (sub: sub.fst == c) null substList; in + if found == null then + c + else + found.snd; in stringAsChars subst s; |