From 0b6bc6cb1a629866da0afa734b00bff09ffd58de Mon Sep 17 00:00:00 2001 From: Eman Resu Date: Sun, 19 Jul 2026 22:27:20 -0400 Subject: [PATCH] fetchurl: partially apply hasPrefix calls --- pkgs/build-support/fetchurl/default.nix | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/fetchurl/default.nix b/pkgs/build-support/fetchurl/default.nix index b91d7a6f1c5d..27a3e543905a 100644 --- a/pkgs/build-support/fetchurl/default.nix +++ b/pkgs/build-support/fetchurl/default.nix @@ -52,6 +52,11 @@ let # "gnu", etc.). sites = builtins.attrNames mirrors; + # partially applied set of functions for each hash type + # this is indexed into with a prefix to avoid re-calling hasPrefix, since it + # takes advantage of partial application for performance reasons + hasAlgoPrefix = lib.genAttrs [ "sha256" "sha1" "sha512" ] hasPrefix; + /** Resolve a URL against the available mirrors. @@ -310,7 +315,7 @@ lib.extendMkDerivation { if hash_.outputHashAlgo == null || hash_.outputHash == "" - || hasPrefix hash_.outputHashAlgo hash_.outputHash + || hasAlgoPrefix.${hash_.outputHashAlgo} hash_.outputHash then hash_.outputHash else