From d0f7511a627d181fc687b3a8a2055817ee7dcfe4 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Sat, 10 Mar 2018 16:27:08 +0000 Subject: [PATCH] Add TrimExcess to TypeDictionary. After adding is finished, this can be used to reduce the memory footprint of the dictionary. --- OpenRA.Game/GameRules/ActorInfo.cs | 3 +++ OpenRA.Game/Primitives/TypeDictionary.cs | 6 ++++++ OpenRA.Game/Server/Server.cs | 2 ++ 3 files changed, 11 insertions(+) diff --git a/OpenRA.Game/GameRules/ActorInfo.cs b/OpenRA.Game/GameRules/ActorInfo.cs index bead7a4a63..ce16bd53c0 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -51,6 +51,8 @@ namespace OpenRA throw new YamlException(e.Message); } } + + traits.TrimExcess(); } catch (YamlException e) { @@ -63,6 +65,7 @@ namespace OpenRA Name = name; foreach (var t in traitInfos) traits.Add(t); + traits.TrimExcess(); } static ITraitInfo LoadTraitInfo(ObjectCreator creator, string traitName, MiniYaml my) diff --git a/OpenRA.Game/Primitives/TypeDictionary.cs b/OpenRA.Game/Primitives/TypeDictionary.cs index 2d3d96feb5..fcb0a63328 100644 --- a/OpenRA.Game/Primitives/TypeDictionary.cs +++ b/OpenRA.Game/Primitives/TypeDictionary.cs @@ -97,6 +97,12 @@ namespace OpenRA.Primitives data.Remove(t); } + public void TrimExcess() + { + foreach (var objs in data.Values) + objs.TrimExcess(); + } + public IEnumerator GetEnumerator() { return WithInterface().GetEnumerator(); diff --git a/OpenRA.Game/Server/Server.cs b/OpenRA.Game/Server/Server.cs index d75470969c..b0ece7cfad 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -140,6 +140,8 @@ namespace OpenRA.Server foreach (var trait in modData.Manifest.ServerTraits) serverTraits.Add(modData.ObjectCreator.CreateObject(trait)); + serverTraits.TrimExcess(); + LobbyInfo = new Session { GlobalSettings =