diff options
author | Robert Hensing <robert@roberthensing.nl> | 2022-03-30 11:19:37 +0200 |
---|---|---|
committer | Robert Hensing <robert@roberthensing.nl> | 2022-03-31 18:31:11 +0200 |
commit | 342a3c32c9834d6e7e7ad44228c8fe59961e6410 (patch) | |
tree | cc11ba09812854887b055069a756855ac4371401 /lib | |
parent | 04c9dd89bf24d9265dc7886ff428a15960dbf3f6 (diff) | |
download | nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar.gz nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar.bz2 nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar.lz nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar.xz nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.tar.zst nixlib-342a3c32c9834d6e7e7ad44228c8fe59961e6410.zip |
lib.sanitizeDerivationName: Optimize the common case
Diffstat (limited to 'lib')
-rw-r--r-- | lib/strings.nix | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/strings.nix b/lib/strings.nix index b2fd495e4c84..3a61f5be68b6 100644 --- a/lib/strings.nix +++ b/lib/strings.nix @@ -756,7 +756,14 @@ rec { sanitizeDerivationName pkgs.hello => "-nix-store-2g75chlbpxlrqn15zlby2dfh8hr9qwbk-hello-2.10" */ - sanitizeDerivationName = string: lib.pipe string [ + sanitizeDerivationName = + let okRegex = match "^[[:alnum:]+_?=-][[:alnum:]+._?=-]*$"; + in + string: + # First detect the common case of already valid strings, to speed those up + if stringLength string <= 207 && okRegex string != null + then unsafeDiscardStringContext string + else lib.pipe string [ # Get rid of string context. This is safe under the assumption that the # resulting string is only used as a derivation name unsafeDiscardStringContext |