From 67f85d7852ef1de5accdb68820d6bbd40740665a Mon Sep 17 00:00:00 2001 From: Marius Ungureanu Date: Tue, 27 Mar 2018 20:45:46 +0300 Subject: [Ide] Cache environment variables at startup. Removes the need for locking on getting the variables. Also, should reduce pressure and grab everything in one go. --- .../MSBuildEvaluationContext.cs | 25 +++++++++++----------- 1 file changed, 13 insertions(+), 12 deletions(-) (limited to 'main/src/core') diff --git a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildEvaluationContext.cs b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildEvaluationContext.cs index 0f37e215f9..8a6cce904c 100644 --- a/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildEvaluationContext.cs +++ b/main/src/core/MonoDevelop.Core/MonoDevelop.Projects.MSBuild/MSBuildEvaluationContext.cs @@ -44,12 +44,12 @@ namespace MonoDevelop.Projects.MSBuild sealed class MSBuildEvaluationContext: IExpressionContext { Dictionary properties = new Dictionary (StringComparer.OrdinalIgnoreCase); - static Dictionary envVars = new Dictionary (); - readonly HashSet propertiesWithTransforms = new HashSet (StringComparer.OrdinalIgnoreCase); - readonly List propertiesWithTransformsSorted = new List (); + readonly IDictionary envVars; + readonly HashSet propertiesWithTransforms; + readonly List propertiesWithTransformsSorted; List searchPaths; - public Dictionary ExistsEvaluationCache { get; } = new Dictionary (); + public Dictionary ExistsEvaluationCache { get; } bool allResolved; MSBuildProject project; @@ -65,16 +65,22 @@ namespace MonoDevelop.Projects.MSBuild public MSBuildEvaluationContext () { + ExistsEvaluationCache = new Dictionary (); + propertiesWithTransforms = new HashSet (StringComparer.OrdinalIgnoreCase); + propertiesWithTransformsSorted = new List (); + envVars = Environment.GetEnvironmentVariables (); } public MSBuildEvaluationContext (MSBuildEvaluationContext parentContext) { this.parentContext = parentContext; this.project = parentContext.project; + this.Log = parentContext.Log; + + this.ExistsEvaluationCache = parentContext.ExistsEvaluationCache; this.propertiesWithTransforms = parentContext.propertiesWithTransforms; this.propertiesWithTransformsSorted = parentContext.propertiesWithTransformsSorted; - this.ExistsEvaluationCache = parentContext.ExistsEvaluationCache; - this.Log = parentContext.Log; + this.envVars = parentContext.envVars; } internal void InitEvaluation (MSBuildProject project) @@ -277,12 +283,7 @@ namespace MonoDevelop.Projects.MSBuild if (parentContext != null) return parentContext.GetPropertyValue (name); - lock (envVars) { - if (!envVars.TryGetValue (name, out val)) - envVars[name] = val = Environment.GetEnvironmentVariable (name); - - return val; - } + return (string)envVars [name]; } public string GetMetadataValue (string name) -- cgit v1.2.3