lib.strings.splitString: compute escaped separator early

Thanks to moving the existing let variable out, this should have
identical performance for non-memoised calls, and improved performance
when caching the separator.
This commit is contained in:
Eman Resu
2026-06-24 17:16:56 -04:00
parent 4a438d1a8a
commit a709ca8240
+3 -3
View File
@@ -1740,11 +1740,11 @@ rec {
:::
*/
splitString =
sep: s:
sep:
let
splits = filter isString (split (escapeRegex (toString sep)) (toString s));
escapedSep = escapeRegex (toString sep);
in
map (addContextFrom s) splits;
s: map (addContextFrom s) (filter isString (split escapedSep (toString s)));
/**
Splits a string into substrings based on a predicate that examines adjacent characters.