From a200d73ef94e671deed5489b7c51382847ee6cb4 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Fri, 15 Dec 2023 19:28:44 +0100 Subject: [PATCH] Use FrozenDictionary in DependencyCollection. Did not test the perf of this at all but it's the perfect use case so... --- Robust.Shared/IoC/DependencyCollection.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Robust.Shared/IoC/DependencyCollection.cs b/Robust.Shared/IoC/DependencyCollection.cs index a063c082c..cc2ec9e15 100644 --- a/Robust.Shared/IoC/DependencyCollection.cs +++ b/Robust.Shared/IoC/DependencyCollection.cs @@ -1,6 +1,6 @@ using System; +using System.Collections.Frozen; using System.Collections.Generic; -using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Reflection; @@ -35,7 +35,7 @@ namespace Robust.Shared.IoC /// /// Immutable and atomically swapped to provide thread safety guarantees. /// - private ImmutableDictionary _services = ImmutableDictionary.Empty; + private FrozenDictionary _services = FrozenDictionary.Empty; // Start fields used for building new services. @@ -310,7 +310,7 @@ namespace Robust.Shared.IoC service.Dispose(); } - _services = ImmutableDictionary.Empty; + _services = FrozenDictionary.Empty; lock (_serviceBuildLock) { @@ -394,7 +394,7 @@ namespace Robust.Shared.IoC // List of all objects we need to inject dependencies into. var injectList = new List(); - var newDeps = _services.ToBuilder(); + var newDeps = _services.ToDictionary(); // First we build every type we have registered but isn't yet built. // This allows us to run this after the content assembly has been loaded. @@ -442,7 +442,7 @@ namespace Robust.Shared.IoC } // Atomically set the new dict of services. - _services = newDeps.ToImmutable(); + _services = newDeps.ToFrozenDictionary(); foreach (var injectedItem in injectList.OfType()) {