lib.strings: Dont create scopes for getName/getVersion

We can create the `parse` function in a scope one level up to avoid recomputing it every time.
This commit is contained in:
adisbladis
2023-12-11 14:47:48 +13:00
parent b571c88ad3
commit bd817120c4

View File

@@ -715,12 +715,12 @@ rec {
getName pkgs.youtube-dl getName pkgs.youtube-dl
=> "youtube-dl" => "youtube-dl"
*/ */
getName = x: getName = let
let parse = drv: (parseDrvName drv).name;
parse = drv: (parseDrvName drv).name; in x:
in if isString x if isString x
then parse x then parse x
else x.pname or (parse x.name); else x.pname or (parse x.name);
/* This function takes an argument that's either a derivation or a /* This function takes an argument that's either a derivation or a
derivation's "name" attribute and extracts the version part from that derivation's "name" attribute and extracts the version part from that
@@ -732,12 +732,12 @@ rec {
getVersion pkgs.youtube-dl getVersion pkgs.youtube-dl
=> "2016.01.01" => "2016.01.01"
*/ */
getVersion = x: getVersion = let
let parse = drv: (parseDrvName drv).version;
parse = drv: (parseDrvName drv).version; in x:
in if isString x if isString x
then parse x then parse x
else x.version or (parse x.name); else x.version or (parse x.name);
/* Extract name with version from URL. Ask for separator which is /* Extract name with version from URL. Ask for separator which is
supposed to start extension. supposed to start extension.