revert lazy archive

This commit is contained in:
Adam Hathcock
2026-01-15 16:40:08 +00:00
parent 63736efcac
commit 810df8a18b
2 changed files with 8 additions and 16 deletions

View File

@@ -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>()
);

View File

@@ -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);