pkgs.formats.ini: add helper to coerce all lists more lazily

Before, we would run a mapAttrs on every attribute, checking listToValue
on each of them. But listToValue is known ahead of time. Instead, we can
only run that map if listToValue isn't null in the first place.
This commit is contained in:
Eman Resu
2026-06-07 08:48:08 -04:00
parent 3198ae073a
commit 8217bcabaf
+8 -2
View File
@@ -256,6 +256,12 @@ optionalAttrs allowAliases aliases
mapAttrs (key: val: if isList val then listToValue val else val)
else
id;
maybeCoerceAllLists =
listToValue:
if listToValue != null then
mapAttrs (_: mapAttrs (key: val: if isList val then listToValue val else val))
else
id;
ignoredArgs = [
"listToValue"
@@ -291,7 +297,7 @@ optionalAttrs allowAliases aliases
generate =
name: value:
pipe value [
(mapAttrs (_: maybeCoerceList listToValue))
(maybeCoerceAllLists listToValue)
(toINI (removeAttrs args ignoredArgs))
(pkgs.writeText name)
];
@@ -343,7 +349,7 @@ optionalAttrs allowAliases aliases
pkgs.writeText name (
toINIWithGlobalSection (removeAttrs args ignoredArgs) {
globalSection = maybeCoerceList listToValue globalSection;
sections = mapAttrs (_: maybeCoerceList listToValue) sections;
sections = maybeCoerceAllLists listToValue sections;
}
);
};