From 2177b88f06a302222db85add7672fe07877a32e7 Mon Sep 17 00:00:00 2001 From: CyrusNajmabadi Date: Mon, 10 Apr 2017 15:28:17 -0700 Subject: [PATCH] Add comments. --- src/Compilers/Core/Portable/Serialization/ObjectBinder.cs | 4 ++++ .../Core/Portable/Serialization/ObjectBinderState.cs | 8 +------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs b/src/Compilers/Core/Portable/Serialization/ObjectBinder.cs index d13838e7072..4283b3f60f5 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 d7b6b0b2be3..edb1412d49c 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; } -- GitLab