Update from Task to ValueTask where I can

This commit is contained in:
Adam Hathcock
2026-01-22 09:18:07 +00:00
parent b9ed2b09c1
commit c5d7407919
19 changed files with 30 additions and 27 deletions

View File

@@ -20,7 +20,7 @@ public static class IAsyncArchiveExtensions
/// <param name="options">Extraction options.</param>
/// <param name="progress">Optional progress reporter for tracking extraction progress.</param>
/// <param name="cancellationToken">Optional cancellation token.</param>
public async Task WriteToDirectoryAsync(
public async ValueTask WriteToDirectoryAsync(
string destinationDirectory,
ExtractionOptions? options = null,
IProgress<ProgressReport>? progress = null,
@@ -47,7 +47,7 @@ public static class IAsyncArchiveExtensions
}
}
private async Task WriteToDirectoryAsyncInternal(
private async ValueTask WriteToDirectoryAsyncInternal(
string destinationDirectory,
ExtractionOptions? options,
IProgress<ProgressReport>? progress,

View File

@@ -119,7 +119,7 @@ public partial class SevenZipArchive : AbstractArchive<SevenZipArchiveEntry, Sev
}
}
private async Task LoadFactoryAsync(
private async ValueTask LoadFactoryAsync(
Stream stream,
CancellationToken cancellationToken = default
)

View File

@@ -27,7 +27,10 @@ internal class MarkHeader : IRarHeader
throw new EndOfStreamException();
}
private static async Task<byte> GetByteAsync(Stream stream, CancellationToken cancellationToken)
private static async ValueTask<byte> GetByteAsync(
Stream stream,
CancellationToken cancellationToken
)
{
var buffer = new byte[1];
var bytesRead = await stream

View File

@@ -1272,7 +1272,7 @@ internal class ArchiveReader
_stream = stream;
}
public async Task OpenAsync(
public async ValueTask OpenAsync(
Stream stream,
bool lookForHeader,
CancellationToken cancellationToken = default
@@ -1425,7 +1425,7 @@ internal class ArchiveReader
return db;
}
public async Task<ArchiveDatabase> ReadDatabaseAsync(
public async ValueTask<ArchiveDatabase> ReadDatabaseAsync(
IPasswordProvider pass,
CancellationToken cancellationToken = default
)

View File

@@ -497,7 +497,7 @@ internal sealed class TarHeader
return true;
}
internal async Task<bool> ReadAsync(AsyncBinaryReader reader)
internal async ValueTask<bool> ReadAsync(AsyncBinaryReader reader)
{
string? longName = null;
string? longLinkName = null;
@@ -637,7 +637,7 @@ internal sealed class TarHeader
}
}
private async Task<string> ReadLongNameAsync(AsyncBinaryReader reader, byte[] buffer)
private async ValueTask<string> ReadLongNameAsync(AsyncBinaryReader reader, byte[] buffer)
{
var size = ReadSize(buffer);

View File

@@ -289,7 +289,7 @@ internal abstract class ZipFilePart : FilePart
return decompressionStream;
}
protected async Task<Stream> GetCryptoStreamAsync(
protected async ValueTask<Stream> GetCryptoStreamAsync(
Stream plainStream,
CancellationToken cancellationToken = default
)
@@ -362,7 +362,7 @@ internal abstract class ZipFilePart : FilePart
return plainStream;
}
protected async Task<Stream> CreateDecompressionStreamAsync(
protected async ValueTask<Stream> CreateDecompressionStreamAsync(
Stream stream,
ZipCompressionMethod method,
CancellationToken cancellationToken = default

View File

@@ -65,7 +65,7 @@ namespace SharpCompress.Compressors.Arj
/// <summary>
/// Asynchronously reads a single bit from the stream. Returns 0 or 1.
/// </summary>
public async Task<int> ReadBitAsync(CancellationToken cancellationToken)
public async ValueTask<int> ReadBitAsync(CancellationToken cancellationToken)
{
if (_bitCount == 0)
{
@@ -90,7 +90,7 @@ namespace SharpCompress.Compressors.Arj
/// <summary>
/// Asynchronously reads n bits (up to 32) from the stream.
/// </summary>
public async Task<int> ReadBitsAsync(int count, CancellationToken cancellationToken)
public async ValueTask<int> ReadBitsAsync(int count, CancellationToken cancellationToken)
{
if (count < 0 || count > 32)
{

View File

@@ -120,7 +120,7 @@ namespace SharpCompress.Compressors.Arj
/// Asynchronously decodes a single element (literal or back-reference) and appends it to _buffer.
/// Returns true if data was added, or false if all input has already been decoded.
/// </summary>
private async Task<bool> DecodeNextAsync(CancellationToken cancellationToken)
private async ValueTask<bool> DecodeNextAsync(CancellationToken cancellationToken)
{
if (_buffer.Count >= _originalSize)
{
@@ -176,7 +176,7 @@ namespace SharpCompress.Compressors.Arj
return res + add;
}
private async Task<int> DecodeValAsync(
private async ValueTask<int> DecodeValAsync(
int from,
int to,
CancellationToken cancellationToken

View File

@@ -76,7 +76,7 @@ public sealed class BZip2Stream : Stream, IStreamStack
/// <param name="compressionMode">Compression Mode</param>
/// <param name="decompressConcatenated">Decompress Concatenated</param>
/// <param name="cancellationToken">Cancellation Token</param>
public static async Task<BZip2Stream> CreateAsync(
public static async ValueTask<BZip2Stream> CreateAsync(
Stream stream,
CompressionMode compressionMode,
bool decompressConcatenated,

View File

@@ -671,7 +671,7 @@ namespace SharpCompress.Compressors.Lzw
}
}
private async Task FillAsync(CancellationToken cancellationToken)
private async ValueTask FillAsync(CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
got = await baseInputStream
@@ -744,7 +744,7 @@ namespace SharpCompress.Compressors.Lzw
tabSuffix[idx] = (byte)idx;
}
private async Task ParseHeaderAsync(CancellationToken cancellationToken)
private async ValueTask ParseHeaderAsync(CancellationToken cancellationToken)
{
headerParsed = true;

View File

@@ -134,7 +134,7 @@ internal class RarBLAKE2spStream : RarStream, IStreamStack
return stream;
}
public static async Task<RarBLAKE2spStream> CreateAsync(
public static async ValueTask<RarBLAKE2spStream> CreateAsync(
IRarUnpack unpack,
FileHeader fileHeader,
MultiVolumeReadOnlyAsyncStream readStream,

View File

@@ -59,7 +59,7 @@ internal class RarCrcStream : RarStream, IStreamStack
return stream;
}
public static async Task<RarCrcStream> CreateAsync(
public static async ValueTask<RarCrcStream> CreateAsync(
IRarUnpack unpack,
FileHeader fileHeader,
MultiVolumeReadOnlyStreamBase readStream,

View File

@@ -32,7 +32,7 @@ public static class BinaryUtils
internal static uint ReadLittleEndianUInt32(this Stream stream) =>
unchecked((uint)ReadLittleEndianInt32(stream));
public static async Task<int> ReadLittleEndianInt32Async(
public static async ValueTask<int> ReadLittleEndianInt32Async(
this Stream stream,
CancellationToken cancellationToken = default
)
@@ -46,7 +46,7 @@ public static class BinaryUtils
return BinaryPrimitives.ReadInt32LittleEndian(bytes);
}
internal static async Task<uint> ReadLittleEndianUInt32Async(
internal static async ValueTask<uint> ReadLittleEndianUInt32Async(
this Stream stream,
CancellationToken cancellationToken = default
) =>

View File

@@ -42,7 +42,7 @@ internal static class MultiByteIntegers
return Output;
}
public static async Task<ulong> ReadXZIntegerAsync(
public static async ValueTask<ulong> ReadXZIntegerAsync(
this BinaryReader reader,
CancellationToken cancellationToken = default,
int MaxBytes = 9

View File

@@ -29,7 +29,7 @@ public class XZFooter
return footer;
}
public static async Task<XZFooter> FromStreamAsync(
public static async ValueTask<XZFooter> FromStreamAsync(
Stream stream,
CancellationToken cancellationToken = default
)

View File

@@ -25,7 +25,7 @@ public class XZHeader
return header;
}
public static async Task<XZHeader> FromStreamAsync(
public static async ValueTask<XZHeader> FromStreamAsync(
Stream stream,
CancellationToken cancellationToken = default
)

View File

@@ -21,7 +21,7 @@ public class XZIndexRecord
return record;
}
public static async Task<XZIndexRecord> FromBinaryReaderAsync(
public static async ValueTask<XZIndexRecord> FromBinaryReaderAsync(
BinaryReader br,
CancellationToken cancellationToken = default
)

View File

@@ -435,7 +435,7 @@ public abstract class AbstractReader<TEntry, TVolume> : IReader, IAsyncReader
protected virtual EntryStream GetEntryStream() =>
CreateEntryStream(Entry.Parts.First().GetCompressedStream());
protected virtual async Task<EntryStream> GetEntryStreamAsync(
protected virtual async ValueTask<EntryStream> GetEntryStreamAsync(
CancellationToken cancellationToken = default
)
{

View File

@@ -128,7 +128,7 @@ public abstract partial class RarReader : AbstractReader<RarReaderEntry, RarVolu
return CreateEntryStream(RarCrcStream.Create(UnpackV2017.Value, Entry.FileHeader, stream));
}
protected override async System.Threading.Tasks.Task<EntryStream> GetEntryStreamAsync(
protected override async System.Threading.Tasks.ValueTask<EntryStream> GetEntryStreamAsync(
System.Threading.CancellationToken cancellationToken = default
)
{