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
This commit is contained in:
Giovanni Bassi 2021-07-02 15:04:17 -03:00 committed by GitHub
parent 2acd98248b
commit 5d679d82cc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 6 deletions

View File

@ -21,6 +21,12 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
); );
let config = CustomConfig::load(toml_config); 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 let mut is_match = context
.try_begin_scan()? .try_begin_scan()?
.set_files(&config.files) .set_files(&config.files)
@ -38,12 +44,6 @@ pub fn module<'a>(name: &str, context: &'a Context) -> Option<Module<'a>> {
} }
} }
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 mut module = Module::new(name, config.description, Some(toml_config));
let parsed = StringFormatter::new(config.format).and_then(|formatter| { let parsed = StringFormatter::new(config.format).and_then(|formatter| {