lib.sanitizeDerivationName: Optimize the common case

This commit is contained in:
Robert Hensing 2022-03-30 11:19:37 +02:00
parent 04c9dd89bf
commit 342a3c32c9

View File

@ -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