From be65ac7c32e3d23ecc5964f11cc8e3c658128ec3 Mon Sep 17 00:00:00 2001 From: "Nicolas B. Pierron" Date: Mon, 13 Jul 2015 23:46:38 +0200 Subject: [PATCH] Issue 8152 - Reduce number of attribute set created by replaceChars. --- lib/strings.nix | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/strings.nix b/lib/strings.nix index 39112407c57..d9f7f6c2db8 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -107,11 +107,13 @@ rec { # replaceChars ["<" ">"] ["<" ">"] "" 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;