From 77d019938498a3ee076c95fdeda39b563a6f8c22 Mon Sep 17 00:00:00 2001 From: Pavlos Touboulidis Date: Thu, 1 May 2014 23:16:01 +0300 Subject: [PATCH] Convert ActorReference field to Lazy Makes LoadMaps 40% faster --- OpenRA.Game/Map/ActorReference.cs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/OpenRA.Game/Map/ActorReference.cs b/OpenRA.Game/Map/ActorReference.cs index dc608123da..d427d51a14 100755 --- a/OpenRA.Game/Map/ActorReference.cs +++ b/OpenRA.Game/Map/ActorReference.cs @@ -8,6 +8,7 @@ */ #endregion +using System; using System.Collections; using System.Collections.Generic; using OpenRA.Primitives; @@ -17,16 +18,24 @@ namespace OpenRA public class ActorReference : IEnumerable { public string Type; - public TypeDictionary InitDict; + public TypeDictionary InitDict + { + get { return initDict.Value; } + } + Lazy initDict; public ActorReference( string type ) : this( type, new Dictionary() ) { } public ActorReference( string type, Dictionary inits ) { Type = type; - InitDict = new TypeDictionary(); - foreach( var i in inits ) - InitDict.Add( LoadInit( i.Key, i.Value ) ); + initDict = Exts.Lazy(() => + { + var dict = new TypeDictionary(); + foreach (var i in inits) + dict.Add(LoadInit(i.Key, i.Value)); + return dict; + }); } static IActorInit LoadInit(string traitName, MiniYaml my)