mirror of https://github.com/ogoun/Zero.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
52 lines
1.2 KiB
52 lines
1.2 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
|
|
namespace MemoryPools.Collections.Linq
|
|
{
|
|
internal class GenericPoolingEnumerable<T> : IPoolingEnumerable<T>
|
|
{
|
|
private IEnumerable<T> _enumerable;
|
|
|
|
public GenericPoolingEnumerable<T> Init(IEnumerable<T> enumerable)
|
|
{
|
|
_enumerable = enumerable;
|
|
return this;
|
|
}
|
|
|
|
public IPoolingEnumerator<T> GetEnumerator()
|
|
{
|
|
var enumerator = _enumerable.GetEnumerator();
|
|
_enumerable = default;
|
|
Pool<GenericPoolingEnumerable<T>>.Return(this);
|
|
return Pool<GenericPoolingEnumerator<T>>.Get().Init(enumerator);
|
|
}
|
|
|
|
IPoolingEnumerator IPoolingEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
}
|
|
internal class GenericEnumerable<T> : IEnumerable<T>
|
|
{
|
|
private IPoolingEnumerable<T> _enumerable;
|
|
|
|
public GenericEnumerable<T> Init(IPoolingEnumerable<T> enumerable)
|
|
{
|
|
_enumerable = enumerable;
|
|
return this;
|
|
}
|
|
|
|
public IEnumerator<T> GetEnumerator()
|
|
{
|
|
var enumerator = _enumerable.GetEnumerator();
|
|
_enumerable = default;
|
|
Pool<GenericEnumerable<T>>.Return(this);
|
|
return Pool<GenericEnumerator<T>>.Get().Init(enumerator);
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
}
|
|
} |