From 14f4431d123be35ed23e49c23b3e3332b2dd4996 Mon Sep 17 00:00:00 2001 From: Silvan Mosberger Date: Mon, 2 Dec 2024 15:54:20 +0100 Subject: [PATCH] lib/modules: Minor performance optimisation Co-Authored-By: Johannes Kirschbauer --- lib/modules.nix | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/modules.nix b/lib/modules.nix index 2294585723ba..f5b8af0e9858 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -763,17 +763,24 @@ let }; }; - mergedType' = - if mergedType ? functor.wrappedDeprecationMessage then - addDeprecatedWrapped mergedType - else - mergedType; - typeSet = - if (bothHave "type") && typesMergeable then - { type = mergedType'; } - else if opt.options ? type && opt.options.type ? functor.wrappedDeprecationMessage then - { type = addDeprecatedWrapped opt.options.type; } + if opt.options ? type then + if res ? type then + if typesMergeable then + { + type = + if mergedType ? functor.wrappedDeprecationMessage then + addDeprecatedWrapped mergedType + else + mergedType; + } + else + # Keep in sync with the same error below! + throw "The option `${showOption loc}' in `${opt._file}' is already declared in ${showFiles res.declarations}." + else if opt.options.type ? functor.wrappedDeprecationMessage then + { type = addDeprecatedWrapped opt.options.type; } + else + {} else {}; @@ -782,9 +789,9 @@ let if bothHave "default" || bothHave "example" || bothHave "description" || - bothHave "apply" || - (bothHave "type" && (! typesMergeable)) + bothHave "apply" then + # Keep in sync with the same error above! throw "The option `${showOption loc}' in `${opt._file}' is already declared in ${showFiles res.declarations}." else let