mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-04 05:25:00 +00:00
revert lazy archive
This commit is contained in:
@@ -23,8 +23,8 @@ public abstract class AbstractArchive<TEntry, TVolume> : IArchive, IAsyncArchive
|
||||
Type = type;
|
||||
ReaderOptions = sourceStream.ReaderOptions;
|
||||
_sourceStream = sourceStream;
|
||||
_lazyVolumes = new LazyReadOnlyCollection<TVolume>(() => LoadVolumes(_sourceStream));
|
||||
_lazyEntries = new LazyReadOnlyCollection<TEntry>(() => LoadEntries(Volumes));
|
||||
_lazyVolumes = new LazyReadOnlyCollection<TVolume>(LoadVolumes(_sourceStream));
|
||||
_lazyEntries = new LazyReadOnlyCollection<TEntry>(LoadEntries(Volumes));
|
||||
_lazyVolumesAsync = new LazyAsyncReadOnlyCollection<TVolume>(
|
||||
LoadVolumesAsync(_sourceStream)
|
||||
);
|
||||
@@ -37,8 +37,8 @@ public abstract class AbstractArchive<TEntry, TVolume> : IArchive, IAsyncArchive
|
||||
{
|
||||
Type = type;
|
||||
ReaderOptions = new();
|
||||
_lazyVolumes = new LazyReadOnlyCollection<TVolume>(() => Enumerable.Empty<TVolume>());
|
||||
_lazyEntries = new LazyReadOnlyCollection<TEntry>(() => Enumerable.Empty<TEntry>());
|
||||
_lazyVolumes = new LazyReadOnlyCollection<TVolume>(Enumerable.Empty<TVolume>());
|
||||
_lazyEntries = new LazyReadOnlyCollection<TEntry>(Enumerable.Empty<TEntry>());
|
||||
_lazyVolumesAsync = new LazyAsyncReadOnlyCollection<TVolume>(
|
||||
AsyncEnumerableEx.Empty<TVolume>()
|
||||
);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using System.Collections;
|
||||
@@ -9,14 +9,10 @@ namespace SharpCompress;
|
||||
internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
|
||||
{
|
||||
private readonly List<T> _backing = new();
|
||||
private readonly Func<IEnumerable<T>> _factory;
|
||||
private IEnumerator<T>? _source;
|
||||
private readonly IEnumerator<T> _source;
|
||||
private bool _fullyLoaded;
|
||||
|
||||
|
||||
public LazyReadOnlyCollection(IEnumerable<T> factory) => _factory = () => factory;
|
||||
|
||||
public LazyReadOnlyCollection(Func<IEnumerable<T>> factory) => _factory = factory;
|
||||
public LazyReadOnlyCollection(IEnumerable<T> source) => _source = source.GetEnumerator();
|
||||
|
||||
private class LazyLoader : IEnumerator<T>
|
||||
{
|
||||
@@ -47,7 +43,7 @@ internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
|
||||
|
||||
#region IEnumerator Members
|
||||
|
||||
object IEnumerator.Current => Current!;
|
||||
object IEnumerator.Current => Current;
|
||||
|
||||
public bool MoveNext()
|
||||
{
|
||||
@@ -56,10 +52,6 @@ internal sealed class LazyReadOnlyCollection<T> : ICollection<T>
|
||||
_index++;
|
||||
return true;
|
||||
}
|
||||
if (_lazyReadOnlyCollection._source == null)
|
||||
{
|
||||
_lazyReadOnlyCollection._source = _lazyReadOnlyCollection._factory().GetEnumerator();
|
||||
}
|
||||
if (!_lazyReadOnlyCollection._fullyLoaded && _lazyReadOnlyCollection._source.MoveNext())
|
||||
{
|
||||
_lazyReadOnlyCollection._backing.Add(_lazyReadOnlyCollection._source.Current);
|
||||
|
||||
Reference in New Issue
Block a user