using System.Collections; using System.Collections.Generic; namespace MemoryPools.Collections.Linq { internal sealed class GenericPoolingEnumerator : IPoolingEnumerator { private IEnumerator _source; public GenericPoolingEnumerator Init(IEnumerator source) { _source = source; return this; } public bool MoveNext() => _source.MoveNext(); public void Reset() => _source.Reset(); object IPoolingEnumerator.Current => Current; public T Current => _source.Current; public void Dispose() { _source.Dispose(); _source = default; Pool>.Return(this); } } internal sealed class GenericEnumerator : IEnumerator { private IPoolingEnumerator _source; public GenericEnumerator Init(IPoolingEnumerator source) { _source = source; return this; } public bool MoveNext() => _source.MoveNext(); public void Reset() => _source.Reset(); object IEnumerator.Current => Current; public T Current => _source.Current; public void Dispose() { _source.Dispose(); _source = default; Pool>.Return(this); } } }