From e4131d58f5ac814aeecc30693846433a4f179511 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Tue, 10 Jan 2023 12:41:16 -0800 Subject: [PATCH] fix new hashsets being allocated on each entity create --- src/EntityStorage.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/EntityStorage.cs b/src/EntityStorage.cs index d2f912d..b0a7b3e 100644 --- a/src/EntityStorage.cs +++ b/src/EntityStorage.cs @@ -18,8 +18,14 @@ namespace MoonTools.ECS public Entity Create() { var entity = new Entity(NextID()); - EntityToComponentTypeIndices.TryAdd(entity.ID, new HashSet()); - EntityToRelationTypeIndices.TryAdd(entity.ID, new HashSet()); + if (!EntityToComponentTypeIndices.ContainsKey(entity.ID)) + { + EntityToComponentTypeIndices.Add(entity.ID, new HashSet()); + } + if (!EntityToRelationTypeIndices.ContainsKey(entity.ID)) + { + EntityToRelationTypeIndices.Add(entity.ID, new HashSet()); + } return entity; }