From 6732046e57616ef50f7c95d6904fe8b731f14b63 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 8476b89ecffc..d0fd06490d1b 100644 --- a/OpenRA.Game/GameRules/ActorInfo.cs +++ b/OpenRA.Game/GameRules/ActorInfo.cs @@ -51,6 +51,8 @@ public ActorInfo(ObjectCreator creator, string name, MiniYaml node) throw new YamlException(e.Message); } } + + traits.TrimExcess(); } catch (YamlException e) { @@ -63,6 +65,7 @@ public ActorInfo(string name, params ITraitInfo[] traitInfos) 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 2d3d96feb573..fcb0a633285b 100644 --- a/OpenRA.Game/Primitives/TypeDictionary.cs +++ b/OpenRA.Game/Primitives/TypeDictionary.cs @@ -97,6 +97,12 @@ void InnerRemove(Type t, object val) 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 d75470969cab..b0ece7cfadc5 100644 --- a/OpenRA.Game/Server/Server.cs +++ b/OpenRA.Game/Server/Server.cs @@ -140,6 +140,8 @@ public Server(IPEndPoint endpoint, ServerSettings settings, ModData modData, boo foreach (var trait in modData.Manifest.ServerTraits) serverTraits.Add(modData.ObjectCreator.CreateObject(trait)); + serverTraits.TrimExcess(); + LobbyInfo = new Session { GlobalSettings =