From 687c5e4738d7e574f918db5b23319ae1ef1040a8 Mon Sep 17 00:00:00 2001 From: Sylvain Audi Date: Fri, 13 Sep 2024 16:02:50 -0400 Subject: [PATCH] Simplify and fix PlatformRegistry dictionary of implementation instances --- Sharpmake/PlatformRegistry.cs | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/Sharpmake/PlatformRegistry.cs b/Sharpmake/PlatformRegistry.cs index 561914796..e255a0f14 100644 --- a/Sharpmake/PlatformRegistry.cs +++ b/Sharpmake/PlatformRegistry.cs @@ -66,7 +66,7 @@ public int GetHashCode(PlatformImplementation obj) private static readonly ConcurrentDictionary s_implementations = new ConcurrentDictionary(new PlatformImplementationComparer()); private static readonly ConcurrentDictionary s_defaultImplementations = new ConcurrentDictionary(); - private static readonly ConcurrentDictionary s_implementationInstances = new ConcurrentDictionary(); // Value is dummy + private static readonly ConcurrentDictionary s_implementationInstances = new ConcurrentDictionary(); private static readonly ConcurrentDictionary s_parsedAssemblies = new ConcurrentDictionary(); // Value is dummy static PlatformRegistry() @@ -499,26 +499,7 @@ private static void EnsureUniquePlatformImplementations(IEnumerable obj.GetType().AssemblyQualifiedName == implType.AssemblyQualifiedName); - object instance = null; - if (result.Key == null) - { - try - { - instance = Activator.CreateInstance(implType); - s_implementationInstances.TryAdd(instance, false); - } - catch (Exception ex) - { - throw new PlatformImplementationCreationException(implType, ex); - } - } - else - { - instance = result.Key; - } - - return instance; + return s_implementationInstances.GetOrAdd(implType, t => Activator.CreateInstance(t)); } private static void RegisterImplementationImpl(Platform platform, Type ifaceType, object implementation)