From 55503bb77bc713c0d0ea4b81c0152d1f90607cf1 Mon Sep 17 00:00:00 2001 From: David Knaack Date: Fri, 3 Apr 2020 18:34:35 +0200 Subject: [PATCH] perf(dotnet): fail faster in the dotnet module (#1034) --- src/modules/dotnet.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/modules/dotnet.rs b/src/modules/dotnet.rs index 592bd59e..2c0169ba 100644 --- a/src/modules/dotnet.rs +++ b/src/modules/dotnet.rs @@ -19,11 +19,20 @@ const PROJECT_JSON_FILE: &str = "project.json"; /// the current directory: /// global.json, project.json, *.sln, *.csproj, *.fsproj, *.xproj pub fn module<'a>(context: &'a Context) -> Option> { - let dotnet_files = get_local_dotnet_files(context).ok()?; - if dotnet_files.is_empty() { + // First check if this is a DotNet Project before doing the O(n) + // check for the version using the JSON files + let is_dotnet_project = context + .try_begin_scan()? + .set_files(&[GLOBAL_JSON_FILE, PROJECT_JSON_FILE]) + .set_extensions(&["sln", "csproj", "fsproj", "xproj"]) + .is_match(); + + if !is_dotnet_project { return None; } + let dotnet_files = get_local_dotnet_files(context).ok()?; + let mut module = context.new_module("dotnet"); let config = DotnetConfig::try_load(module.config);