mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 20:55:31 +03:00
lib.modules: Refactor option scanning slightly
This scans the options with fewer function calls, improving performance. It also removes a let Env from the happy flow of the new logic.
This commit is contained in:
parent
58a8a48e9d
commit
0c09eb343d
1 changed files with 8 additions and 10 deletions
|
@ -9,7 +9,6 @@ let
|
||||||
catAttrs
|
catAttrs
|
||||||
concatLists
|
concatLists
|
||||||
concatMap
|
concatMap
|
||||||
count
|
|
||||||
elem
|
elem
|
||||||
filter
|
filter
|
||||||
findFirst
|
findFirst
|
||||||
|
@ -492,20 +491,16 @@ rec {
|
||||||
loc = prefix ++ [name];
|
loc = prefix ++ [name];
|
||||||
defns = defnsByName.${name} or [];
|
defns = defnsByName.${name} or [];
|
||||||
defns' = defnsByName'.${name} or [];
|
defns' = defnsByName'.${name} or [];
|
||||||
nrOptions = count (m: isOption m.options) decls;
|
optionDecls = filter (m: isOption m.options) decls;
|
||||||
in
|
in
|
||||||
if nrOptions == length decls then
|
if length optionDecls == length decls then
|
||||||
let opt = fixupOptionType loc (mergeOptionDecls loc decls);
|
let opt = fixupOptionType loc (mergeOptionDecls loc decls);
|
||||||
in {
|
in {
|
||||||
matchedOptions = evalOptionValue loc opt defns';
|
matchedOptions = evalOptionValue loc opt defns';
|
||||||
unmatchedDefns = [];
|
unmatchedDefns = [];
|
||||||
}
|
}
|
||||||
else if nrOptions != 0 then
|
else if optionDecls != [] then
|
||||||
let
|
if (lib.head optionDecls).options.type.name == "submodule"
|
||||||
firstOption = findFirst (m: isOption m.options) "" decls;
|
|
||||||
firstNonOption = findFirst (m: !isOption m.options) "" decls;
|
|
||||||
in
|
|
||||||
if firstOption.options.type.name == "submodule"
|
|
||||||
then
|
then
|
||||||
let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls));
|
let opt = fixupOptionType loc (mergeOptionDecls loc (map optionTreeToOption decls));
|
||||||
in {
|
in {
|
||||||
|
@ -513,7 +508,10 @@ rec {
|
||||||
unmatchedDefns = [];
|
unmatchedDefns = [];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
throw "The option `${showOption loc}' in `${firstOption._file}' is a prefix of options in `${firstNonOption._file}'."
|
let
|
||||||
|
firstNonOption = findFirst (m: !isOption m.options) "" decls;
|
||||||
|
in
|
||||||
|
throw "The option `${showOption loc}' in `${(lib.head optionDecls)._file}' is a prefix of options in `${firstNonOption._file}'."
|
||||||
else
|
else
|
||||||
mergeModules' loc decls defns) declsByName;
|
mergeModules' loc decls defns) declsByName;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue