From b875051f7e938703dd1f2e7ac153597df9f62fb5 Mon Sep 17 00:00:00 2001 From: Alex Basau Date: Wed, 20 Aug 2025 18:56:35 -0700 Subject: [PATCH 1/3] Exit after replacing an item in DictionarySlim --- source/Handlebars/Collections/DictionarySlim.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/source/Handlebars/Collections/DictionarySlim.cs b/source/Handlebars/Collections/DictionarySlim.cs index 3433e20a..d361f624 100644 --- a/source/Handlebars/Collections/DictionarySlim.cs +++ b/source/Handlebars/Collections/DictionarySlim.cs @@ -183,7 +183,10 @@ public void AddOrReplace(in TKey key, in TValue value) (uint)i < (uint)entries.Length; i = entries[i].Next) { if (_comparer.Equals(key, entries[i].Key)) + { entries[i].Value = value; + return; + } if (collisionCount == entries.Length) { // The chain of entries forms a loop; which means a concurrent update has happened. From e309dfc15ff24fd68c51e106d8577cdb3a23d729 Mon Sep 17 00:00:00 2001 From: Alex Basau Date: Wed, 20 Aug 2025 18:57:06 -0700 Subject: [PATCH 2/3] Clear "Configuration" when releasing BindingContext --- source/Handlebars/Pools/BindingContext.Pool.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Handlebars/Pools/BindingContext.Pool.cs b/source/Handlebars/Pools/BindingContext.Pool.cs index 8fc6a999..7d616477 100644 --- a/source/Handlebars/Pools/BindingContext.Pool.cs +++ b/source/Handlebars/Pools/BindingContext.Pool.cs @@ -46,6 +46,8 @@ internal struct BindingContextPolicy : IInternalObjectPoolPolicy public bool Return(BindingContext item) { + item.Configuration = null; + item.Root = null; item.Value = null; item.ParentContext = null; From 364d6dc2164f48bb78d4ed8e0f074eaede8b05c5 Mon Sep 17 00:00:00 2001 From: Alex Basau Date: Wed, 20 Aug 2025 19:02:44 -0700 Subject: [PATCH 3/3] A comment to solicit discussion --- source/Handlebars/Collections/WeakCollection.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source/Handlebars/Collections/WeakCollection.cs b/source/Handlebars/Collections/WeakCollection.cs index 1b6d2bd5..e01ef1ef 100644 --- a/source/Handlebars/Collections/WeakCollection.cs +++ b/source/Handlebars/Collections/WeakCollection.cs @@ -13,6 +13,8 @@ public class WeakCollection : IEnumerable where T : class public void Add(T value) { + // Need a way to reset _firstAvailableIndex periodically + for (var index = _firstAvailableIndex; index < _store.Count; index++) { if (_store[index] == null)