summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoradisbladis <adisbladis@gmail.com>2024-09-03 01:11:13 +1200
committeradisbladis <adisbladis@gmail.com>2024-09-03 01:15:51 +1200
commit8a207815796726eea82c690ef6d8c52ad9d87707 (patch)
tree6b6f7edc20c34fe0735f36ffa543ed6e59c7b38c
parentlib.systems: add rustTarget for riscv32 (diff)
downloadnixpkgs-8a207815796726eea82c690ef6d8c52ad9d87707.tar.gz
lib.strings.trimWith: Refactor scoping
I wanted to use this instead of [my ownimplementation](https://github.com/nix-community/pyproject.nix/blob/65d4134/lib/util.nix#L18-L23) and got a small performance regression.
-rw-r--r--lib/strings.nix7
1 files changed, 4 insertions, 3 deletions
diff --git a/lib/strings.nix b/lib/strings.nix
index 54a5b9c67434..ffde541c6958 100644
--- a/lib/strings.nix
+++ b/lib/strings.nix
@@ -408,7 +408,6 @@ rec {
start ? false,
end ? false,
}:
- s:
let
# Define our own whitespace character class instead of using
# `[:space:]`, which is not well-defined.
@@ -425,12 +424,14 @@ rec {
"(.*[^${chars}])[${chars}]*"
else
"(.*)";
-
+ in
+ s:
+ let
# If the string was empty or entirely whitespace,
# then the regex may not match and `res` will be `null`.
res = match regex s;
in
- optionalString (res != null) (head res);
+ optionalString (res != null) (head res);
/**
Construct a Unix-style, colon-separated search path consisting of