From 8352575043f297944ec7c6daaa818483bac169f8 Mon Sep 17 00:00:00 2001 From: mlemanczyk Date: Sat, 1 Jul 2023 14:08:19 +0200 Subject: [PATCH] RecyclableLongList.Enumerator & .VersionedEnumerator will clear the current value only when it's reference type. Tiny cleanup. --- .../RecyclableLongList.Enumerator.cs | 10 ++++++---- .../RecyclableLongList.VersionedEnumerator.cs | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Recyclable.Collections/RecyclableLongList.Enumerator.cs b/Recyclable.Collections/RecyclableLongList.Enumerator.cs index 01c94dd..65fb776 100644 --- a/Recyclable.Collections/RecyclableLongList.Enumerator.cs +++ b/Recyclable.Collections/RecyclableLongList.Enumerator.cs @@ -11,8 +11,6 @@ namespace Recyclable.Collections private static readonly T _default = default; #nullable restore - private static readonly bool _isReferenceType = !typeof(T).IsValueType; - private int _currentBlockIndex; private int _currentItemIndex; private readonly RecyclableLongList _list; @@ -69,14 +67,18 @@ namespace Recyclable.Collections public void Reset() { - _current = _default; + if (NeedsClearing) + { + _current = _default; + } + _currentBlockIndex = 0; _currentItemIndex = 0; } public void Dispose() { - if (_isReferenceType) + if (NeedsClearing) { _current = _default; } diff --git a/Recyclable.Collections/RecyclableLongList.VersionedEnumerator.cs b/Recyclable.Collections/RecyclableLongList.VersionedEnumerator.cs index 9e4ea5e..a634914 100644 --- a/Recyclable.Collections/RecyclableLongList.VersionedEnumerator.cs +++ b/Recyclable.Collections/RecyclableLongList.VersionedEnumerator.cs @@ -14,8 +14,6 @@ namespace Recyclable.Collections private static readonly T _default = default; #nullable restore - private static readonly bool _isReferenceType = !typeof(T).IsValueType; - private int _currentBlockIndex; private int _currentItemIndex; private readonly RecyclableLongList _list; @@ -88,14 +86,18 @@ namespace Recyclable.Collections throw new InvalidOperationException(); } - _current = _default; + if (NeedsClearing) + { + _current = _default; + } + _currentBlockIndex = 0; _currentItemIndex = 0; } public void Dispose() { - if (_isReferenceType) + if (NeedsClearing) { _current = _default; }