diff --git a/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs b/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs index d13838e70727b2089cf76f5ef16d6c74a950ee52..4283b3f60f5d06e94f290d512c634d39da1b2f65 100644 --- a/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs +++ b/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs @@ -27,11 +27,13 @@ public static ObjectBinderState AllocateStateCopy() { lock (s_gate) { + // If we have any pooled copies, then just return one of those. if (s_pool.Count > 0) { return s_pool.Pop(); } + // Otherwise, create copy from our current state and return that. var state = ObjectBinderState.Create(s_version); state.CopyFrom(s_state); @@ -43,6 +45,8 @@ public static void FreeStateCopy(ObjectBinderState state) { lock (s_gate) { + // If our version changed between now and when we returned the state object, + // then we don't want to keep around this verion in the pool. if (state.Version == s_version) { if (s_pool.Count < 128) diff --git a/src/Compilers/Core/Portable/Serialization/ObjectBinderState.cs b/src/Compilers/Core/Portable/Serialization/ObjectBinderState.cs index d7b6b0b2be3b97c21d4cddf2749fe652f91df324..edb1412d49c99d3a62b60788c84248278f7d8792 100644 --- a/src/Compilers/Core/Portable/Serialization/ObjectBinderState.cs +++ b/src/Compilers/Core/Portable/Serialization/ObjectBinderState.cs @@ -29,13 +29,6 @@ internal struct ObjectBinderState public static ObjectBinderState Create(int version) => new ObjectBinderState(version, new Dictionary(), new List(), new List>()); - public void Clear() - { - _typeToIndex.Clear(); - _types.Clear(); - _typeReaders.Clear(); - } - public void CopyFrom(ObjectBinderState other) { if (_types.Count == 0) @@ -82,6 +75,7 @@ public bool RegisterTypeReader(Type type, Func typeReader) { if (_typeToIndex.ContainsKey(type)) { + // We already knew about this type, nothing to register. return false; }