From 5d679d82ccece504351a11a056e90663eca70222 Mon Sep 17 00:00:00 2001 From: Giovanni Bassi Date: Fri, 2 Jul 2021 15:04:17 -0300 Subject: [PATCH] perf: Improve custom config OS (#2843) Related to #2750 and #2751. Moving the OS check before other checks so that there is no performance hit for running the match in the incorrect OS --- src/modules/custom.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/modules/custom.rs b/src/modules/custom.rs index 02c2f6f1..ee1e0738 100644 --- a/src/modules/custom.rs +++ b/src/modules/custom.rs @@ -21,6 +21,12 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option> { ); let config = CustomConfig::load(toml_config); + if let Some(os) = config.os { + if os != env::consts::OS && !(os == "unix" && cfg!(unix)) { + return None; + } + } + let mut is_match = context .try_begin_scan()? .set_files(&config.files) @@ -38,12 +44,6 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option> { } } - if let Some(os) = config.os { - if os != env::consts::OS && !(os == "unix" && cfg!(unix)) { - return None; - } - } - let mut module = Module::new(name, config.description, Some(toml_config)); let parsed = StringFormatter::new(config.format).and_then(|formatter| {