From ee2cbc8051bff0f4ea92cb1fc9aaecb406d4f145 Mon Sep 17 00:00:00 2001 From: Adam Hathcock Date: Mon, 13 Oct 2025 17:02:41 +0100 Subject: [PATCH] fmt --- src/SharpCompress/Common/Arc/ArcFilePart.cs | 13 +- .../Compressors/Filters/DeltaFilter.cs | 2 +- .../Compressors/Lzw/LzwConstants.cs | 2 +- .../Compressors/Lzw/LzwStream.cs | 30 +- .../Compressors/RLE90/RunLength90Stream.cs | 6 +- .../Compressors/Squeezed/SqueezedStream.cs | 6 +- .../ZStandard/CompressionStream.cs | 64 +- .../Compressors/ZStandard/Compressor.cs | 30 +- .../Compressors/ZStandard/Constants.cs | 2 +- .../ZStandard/DecompressionStream.cs | 59 +- .../Compressors/ZStandard/Decompressor.cs | 36 +- .../Compressors/ZStandard/SafeHandles.cs | 10 +- .../ZStandard/SynchronizationWrapper.cs | 2 +- .../ZStandard/Unsafe/BIT_CStream_t.cs | 2 +- .../ZStandard/Unsafe/BIT_DStream_status.cs | 2 +- .../Compressors/ZStandard/Unsafe/Bitstream.cs | 174 ++- .../ZStandard/Unsafe/BlockSummary.cs | 2 +- .../ZStandard/Unsafe/COVER_best_s.cs | 2 +- .../ZStandard/Unsafe/COVER_ctx_t.cs | 2 +- .../ZStandard/Unsafe/COVER_map_s.cs | 2 +- .../ZStandard/Unsafe/COVER_segment_t.cs | 2 +- .../Compressors/ZStandard/Unsafe/Cover.cs | 17 +- .../ZStandard/Unsafe/DTableDesc.cs | 2 +- .../ZStandard/Unsafe/EStats_ress_t.cs | 2 +- .../ZStandard/Unsafe/EntropyCommon.cs | 20 +- .../ZStandard/Unsafe/EstimatedBlockSize.cs | 2 +- .../ZStandard/Unsafe/FASTCOVER_ctx_t.cs | 2 +- .../Unsafe/FASTCOVER_tryParameters_data_s.cs | 2 +- .../ZStandard/Unsafe/FSE_DTableHeader.cs | 2 +- .../ZStandard/Unsafe/FSE_DecompressWksp.cs | 2 +- .../Compressors/ZStandard/Unsafe/Fastcover.cs | 56 +- .../Compressors/ZStandard/Unsafe/Fse.cs | 21 +- .../ZStandard/Unsafe/FseCompress.cs | 79 +- .../ZStandard/Unsafe/FseDecompress.cs | 45 +- .../ZStandard/Unsafe/HIST_checkInput_e.cs | 2 +- .../Unsafe/HUF_CompressWeightsWksp.cs | 2 +- .../Unsafe/HUF_DecompressFastArgs.cs | 2 +- .../Unsafe/HUF_ReadDTableX1_Workspace.cs | 2 +- .../Unsafe/HUF_ReadDTableX2_Workspace.cs | 20 +- .../Unsafe/HUF_buildCTable_wksp_tables.cs | 22 +- .../ZStandard/Unsafe/HUF_compress_tables_t.cs | 10 +- .../Compressors/ZStandard/Unsafe/Hist.cs | 11 +- .../ZStandard/Unsafe/HufCompress.cs | 76 +- .../ZStandard/Unsafe/HufDecompress.cs | 175 +-- .../Compressors/ZStandard/Unsafe/Mem.cs | 4 +- .../ZStandard/Unsafe/RSyncState_t.cs | 2 +- .../ZStandard/Unsafe/RawSeqStore_t.cs | 8 +- .../ZStandard/Unsafe/RoundBuff_t.cs | 2 +- .../Compressors/ZStandard/Unsafe/SeqDef_s.cs | 2 +- .../ZStandard/Unsafe/XXH32_canonical_t.cs | 2 +- .../Compressors/ZStandard/Unsafe/Xxhash.cs | 29 +- .../ZStandard/Unsafe/ZDICT_cover_params_t.cs | 2 +- .../ZStandard/Unsafe/ZSTDMT_bufferPool_s.cs | 2 +- .../ZStandard/Unsafe/ZSTD_CDict_s.cs | 2 +- .../ZStandard/Unsafe/ZSTD_DDictHashSet.cs | 2 +- .../ZStandard/Unsafe/ZSTD_DDict_s.cs | 2 +- .../ZStandard/Unsafe/ZSTD_DefaultPolicy_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_ErrorCode.cs | 2 +- .../ZStandard/Unsafe/ZSTD_OptPrice_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_SequencePosition.cs | 2 +- .../Unsafe/ZSTD_buffered_policy_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_cStreamStage.cs | 2 +- .../Unsafe/ZSTD_compResetPolicy_e.cs | 2 +- .../Unsafe/ZSTD_compressionStage_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_customMem.cs | 2 +- .../Unsafe/ZSTD_cwksp_static_alloc_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_dStreamStage.cs | 2 +- .../Unsafe/ZSTD_dictContentType_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_dictUses_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_entropyDTables_t.cs | 32 +- .../Unsafe/ZSTD_forceIgnoreChecksum_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_frameHeader.cs | 2 +- .../ZStandard/Unsafe/ZSTD_frameProgression.cs | 2 +- .../ZStandard/Unsafe/ZSTD_frameType_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_fseCTables_t.cs | 2 +- .../ZStandard/Unsafe/ZSTD_hufCTables_t.cs | 10 +- .../ZStandard/Unsafe/ZSTD_inBuffer_s.cs | 2 +- .../Unsafe/ZSTD_indexResetPolicy_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_localDict.cs | 2 +- .../ZStandard/Unsafe/ZSTD_longLengthType_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_match_t.cs | 2 +- .../ZStandard/Unsafe/ZSTD_outBuffer_s.cs | 2 +- .../ZStandard/Unsafe/ZSTD_parameters.cs | 2 +- .../ZStandard/Unsafe/ZSTD_resetTarget_e.cs | 2 +- .../ZStandard/Unsafe/ZSTD_seqSymbol.cs | 2 +- .../ZStandard/Unsafe/ZSTD_sequenceFormat_e.cs | 2 +- .../Unsafe/ZSTD_tableFillPurpose_e.cs | 2 +- .../Compressors/ZStandard/Unsafe/Zdict.cs | 36 +- .../ZStandard/Unsafe/ZstdCompress.cs | 1017 ++++++----------- .../ZStandard/Unsafe/ZstdCompressInternal.cs | 480 ++++---- .../ZStandard/Unsafe/ZstdCompressLiterals.cs | 55 +- .../ZStandard/Unsafe/ZstdCompressSequences.cs | 581 +++++----- .../Unsafe/ZstdCompressSuperblock.cs | 24 +- .../Compressors/ZStandard/Unsafe/ZstdCwksp.cs | 19 +- .../Compressors/ZStandard/Unsafe/ZstdDdict.cs | 26 +- .../ZStandard/Unsafe/ZstdDecompress.cs | 659 +++++------ .../ZStandard/Unsafe/ZstdDecompressBlock.cs | 592 ++++------ .../Unsafe/ZstdDecompressInternal.cs | 378 +++--- .../ZStandard/Unsafe/ZstdDoubleFast.cs | 170 +-- .../Compressors/ZStandard/Unsafe/ZstdFast.cs | 72 +- .../ZStandard/Unsafe/ZstdInternal.cs | 540 +++++---- .../Compressors/ZStandard/Unsafe/ZstdLazy.cs | 754 ++++-------- .../Compressors/ZStandard/Unsafe/ZstdLdm.cs | 85 +- .../ZStandard/Unsafe/ZstdLdmGeartab.cs | 530 ++++----- .../Compressors/ZStandard/Unsafe/ZstdOpt.cs | 306 +++-- .../ZStandard/Unsafe/ZstdPresplit.cs | 15 +- .../ZStandard/Unsafe/ZstdmtCompress.cs | 122 +- .../Compressors/ZStandard/Unsafe/inBuff_t.cs | 2 +- .../ZStandard/Unsafe/ldmRollingHashState_t.cs | 2 +- .../ZStandard/Unsafe/ldmState_t.cs | 20 +- .../ZStandard/Unsafe/offsetCount_t.cs | 2 +- .../ZStandard/Unsafe/rankValCol_t.cs | 2 +- .../ZStandard/Unsafe/repcodes_s.cs | 2 +- .../ZStandard/Unsafe/sortedSymbol_t.cs | 2 +- .../Compressors/ZStandard/UnsafeHelper.cs | 38 +- src/SharpCompress/Factories/ArcFactory.cs | 2 +- src/SharpCompress/IO/IStreamStack.cs | 212 ++-- src/SharpCompress/Readers/Arc/ArcReader.cs | 2 +- 118 files changed, 3268 insertions(+), 4662 deletions(-) diff --git a/src/SharpCompress/Common/Arc/ArcFilePart.cs b/src/SharpCompress/Common/Arc/ArcFilePart.cs index 23173385..da936236 100644 --- a/src/SharpCompress/Common/Arc/ArcFilePart.cs +++ b/src/SharpCompress/Common/Arc/ArcFilePart.cs @@ -45,20 +45,13 @@ public class ArcFilePart : FilePart ); break; case CompressionType.RLE90: - compressedStream = new RunLength90Stream( - _stream, - (int)Header.CompressedSize - ); + compressedStream = new RunLength90Stream(_stream, (int)Header.CompressedSize); break; case CompressionType.Squeezed: compressedStream = new SqueezeStream(_stream, (int)Header.CompressedSize); break; case CompressionType.Crunched: - compressedStream = new ArcLzwStream( - _stream, - (int)Header.CompressedSize, - true - ); + compressedStream = new ArcLzwStream(_stream, (int)Header.CompressedSize, true); break; default: throw new NotSupportedException( @@ -71,4 +64,4 @@ public class ArcFilePart : FilePart } internal override Stream? GetRawStream() => _stream; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Filters/DeltaFilter.cs b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs index 2f1c2b2e..5f7593ce 100644 --- a/src/SharpCompress/Compressors/Filters/DeltaFilter.cs +++ b/src/SharpCompress/Compressors/Filters/DeltaFilter.cs @@ -32,4 +32,4 @@ internal class DeltaFilter : Filter return count; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Lzw/LzwConstants.cs b/src/SharpCompress/Compressors/Lzw/LzwConstants.cs index 7e8a6399..d36210e8 100644 --- a/src/SharpCompress/Compressors/Lzw/LzwConstants.cs +++ b/src/SharpCompress/Compressors/Lzw/LzwConstants.cs @@ -61,4 +61,4 @@ public sealed class LzwConstants public const int INIT_BITS = 9; private LzwConstants() { } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/Lzw/LzwStream.cs b/src/SharpCompress/Compressors/Lzw/LzwStream.cs index c6a0d09b..1dd2736f 100644 --- a/src/SharpCompress/Compressors/Lzw/LzwStream.cs +++ b/src/SharpCompress/Compressors/Lzw/LzwStream.cs @@ -46,7 +46,7 @@ namespace SharpCompress.Compressors.Lzw; public class LzwStream : Stream, IStreamStack { #if DEBUG_STREAMS - long IStreamStack.InstanceId { get; set; } + long IStreamStack.InstanceId { get; set; } #endif int IStreamStack.DefaultBufferSize { get; set; } @@ -112,7 +112,7 @@ public class LzwStream : Stream, IStreamStack { this.baseInputStream = baseInputStream; #if DEBUG_STREAMS - this.DebugConstruct(typeof(LzwStream)); + this.DebugConstruct(typeof(LzwStream)); #endif } @@ -237,13 +237,13 @@ public class LzwStream : Stream, IStreamStack // read next code int pos = lBitPos >> 3; int code = - ( ( - (lData[pos] & 0xFF) - | ((lData[pos + 1] & 0xFF) << 8) - | ((lData[pos + 2] & 0xFF) << 16) - ) >> (lBitPos & 0x7) - ) & lBitMask; + ( + (lData[pos] & 0xFF) + | ((lData[pos + 1] & 0xFF) << 8) + | ((lData[pos + 2] & 0xFF) << 16) + ) >> (lBitPos & 0x7) + ) & lBitMask; lBitPos += lNBits; @@ -251,9 +251,7 @@ public class LzwStream : Stream, IStreamStack if (lOldCode == -1) { if (code >= 256) - throw new IncompleteArchiveException( - "corrupt input: " + code + " > 255" - ); + throw new IncompleteArchiveException("corrupt input: " + code + " > 255"); lFinChar = (byte)(lOldCode = code); buffer[offset++] = lFinChar; @@ -423,10 +421,10 @@ public class LzwStream : Stream, IStreamStack { throw new ArchiveException( "Stream compressed with " - + maxBits - + " bits, but decompression can only handle " - + LzwConstants.MAX_BITS - + " bits." + + maxBits + + " bits, but decompression can only handle " + + LzwConstants.MAX_BITS + + " bits." ); } @@ -564,7 +562,7 @@ public class LzwStream : Stream, IStreamStack { isClosed = true; #if DEBUG_STREAMS - this.DebugDispose(typeof(LzwStream)); + this.DebugDispose(typeof(LzwStream)); #endif if (IsStreamOwner) { diff --git a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs index d70685f9..165bfb54 100644 --- a/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs +++ b/src/SharpCompress/Compressors/RLE90/RunLength90Stream.cs @@ -11,7 +11,7 @@ namespace SharpCompress.Compressors.RLE90; public class RunLength90Stream : Stream, IStreamStack { #if DEBUG_STREAMS - long IStreamStack.InstanceId { get; set; } + long IStreamStack.InstanceId { get; set; } #endif int IStreamStack.DefaultBufferSize { get; set; } @@ -40,14 +40,14 @@ public class RunLength90Stream : Stream, IStreamStack _stream = stream; _compressedSize = compressedSize; #if DEBUG_STREAMS - this.DebugConstruct(typeof(RunLength90Stream)); + this.DebugConstruct(typeof(RunLength90Stream)); #endif } protected override void Dispose(bool disposing) { #if DEBUG_STREAMS - this.DebugDispose(typeof(RunLength90Stream)); + this.DebugDispose(typeof(RunLength90Stream)); #endif base.Dispose(disposing); } diff --git a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs index 95e8b0dc..f60b415a 100644 --- a/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs +++ b/src/SharpCompress/Compressors/Squeezed/SqueezedStream.cs @@ -12,7 +12,7 @@ namespace SharpCompress.Compressors.Squeezed; public class SqueezeStream : Stream, IStreamStack { #if DEBUG_STREAMS - long IStreamStack.InstanceId { get; set; } + long IStreamStack.InstanceId { get; set; } #endif int IStreamStack.DefaultBufferSize { get; set; } @@ -42,14 +42,14 @@ public class SqueezeStream : Stream, IStreamStack _stream = stream; _compressedSize = compressedSize; #if DEBUG_STREAMS - this.DebugConstruct(typeof(SqueezeStream)); + this.DebugConstruct(typeof(SqueezeStream)); #endif } protected override void Dispose(bool disposing) { #if DEBUG_STREAMS - this.DebugDispose(typeof(SqueezeStream)); + this.DebugDispose(typeof(SqueezeStream)); #endif base.Dispose(disposing); } diff --git a/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs b/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs index 5dc293e1..92de03b3 100644 --- a/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs +++ b/src/SharpCompress/Compressors/ZStandard/CompressionStream.cs @@ -77,7 +77,7 @@ public class CompressionStream : Stream #if !NETSTANDARD2_0 && !NETFRAMEWORK public override async ValueTask DisposeAsync() #else - public async Task DisposeAsync() + public async Task DisposeAsync() #endif { if (compressor == null) @@ -149,8 +149,8 @@ public class CompressionStream : Stream public override void Write(ReadOnlySpan buffer) => WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue); #else - public void Write(ReadOnlySpan buffer) => - WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue); + public void Write(ReadOnlySpan buffer) => + WriteInternal(buffer, ZSTD_EndDirective.ZSTD_e_continue); #endif private void WriteInternal(ReadOnlySpan buffer, ZSTD_EndDirective directive) @@ -172,9 +172,7 @@ public class CompressionStream : Stream if (written > 0) innerStream.Write(outputBuffer, 0, written); } while ( - directive == ZSTD_EndDirective.ZSTD_e_continue - ? input.pos < input.size - : remaining > 0 + directive == ZSTD_EndDirective.ZSTD_e_continue ? input.pos < input.size : remaining > 0 ); } @@ -185,11 +183,11 @@ public class CompressionStream : Stream CancellationToken cancellationToken = default ) #else - private async Task WriteInternalAsync( - ReadOnlyMemory? buffer, - ZSTD_EndDirective directive, - CancellationToken cancellationToken = default - ) + private async Task WriteInternalAsync( + ReadOnlyMemory? buffer, + ZSTD_EndDirective directive, + CancellationToken cancellationToken = default + ) #endif { @@ -213,12 +211,10 @@ public class CompressionStream : Stream var written = (int)output.pos; if (written > 0) await innerStream - .WriteAsync(outputBuffer, 0, written, cancellationToken) - .ConfigureAwait(false); + .WriteAsync(outputBuffer, 0, written, cancellationToken) + .ConfigureAwait(false); } while ( - directive == ZSTD_EndDirective.ZSTD_e_continue - ? input.pos < input.size - : remaining > 0 + directive == ZSTD_EndDirective.ZSTD_e_continue ? input.pos < input.size : remaining > 0 ); } @@ -229,8 +225,7 @@ public class CompressionStream : Stream int offset, int count, CancellationToken cancellationToken - ) => - WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); + ) => WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken).AsTask(); public override async ValueTask WriteAsync( ReadOnlyMemory buffer, @@ -240,19 +235,19 @@ public class CompressionStream : Stream .ConfigureAwait(false); #else - public override Task WriteAsync( - byte[] buffer, - int offset, - int count, - CancellationToken cancellationToken - ) => WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken); + public override Task WriteAsync( + byte[] buffer, + int offset, + int count, + CancellationToken cancellationToken + ) => WriteAsync(new ReadOnlyMemory(buffer, offset, count), cancellationToken); - public async Task WriteAsync( - ReadOnlyMemory buffer, - CancellationToken cancellationToken = default - ) => - await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken) - .ConfigureAwait(false); + public async Task WriteAsync( + ReadOnlyMemory buffer, + CancellationToken cancellationToken = default + ) => + await WriteInternalAsync(buffer, ZSTD_EndDirective.ZSTD_e_continue, cancellationToken) + .ConfigureAwait(false); #endif internal unsafe nuint CompressStream( @@ -267,9 +262,9 @@ public class CompressionStream : Stream input.src = inputBufferPtr; output.dst = outputBufferPtr; return compressor - .NotNull() - .CompressStream(ref input, ref output, directive) - .EnsureZstdSuccess(); + .NotNull() + .CompressStream(ref input, ref output, directive) + .EnsureZstdSuccess(); } } @@ -285,8 +280,7 @@ public class CompressionStream : Stream set => throw new NotSupportedException(); } - public override long Seek(long offset, SeekOrigin origin) => - throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException(); diff --git a/src/SharpCompress/Compressors/ZStandard/Compressor.cs b/src/SharpCompress/Compressors/ZStandard/Compressor.cs index 8e99d24c..66860601 100644 --- a/src/SharpCompress/Compressors/ZStandard/Compressor.cs +++ b/src/SharpCompress/Compressors/ZStandard/Compressor.cs @@ -62,9 +62,9 @@ public unsafe class Compressor : IDisposable { using var cctx = handle.Acquire(); fixed (byte* dictPtr = dict) - Unsafe.Methods - .ZSTD_CCtx_loadDictionary(cctx, dictPtr, (nuint)dict.Length) - .EnsureZstdSuccess(); + Unsafe + .Methods.ZSTD_CCtx_loadDictionary(cctx, dictPtr, (nuint)dict.Length) + .EnsureZstdSuccess(); } public Compressor(int level = DefaultCompressionLevel) @@ -96,15 +96,15 @@ public unsafe class Compressor : IDisposable { using var cctx = handle.Acquire(); return (int) - Unsafe.Methods - .ZSTD_compress2( - cctx, - destPtr, - (nuint)dest.Length, - srcPtr, - (nuint)src.Length - ) - .EnsureZstdSuccess(); + Unsafe + .Methods.ZSTD_compress2( + cctx, + destPtr, + (nuint)dest.Length, + srcPtr, + (nuint)src.Length + ) + .EnsureZstdSuccess(); } } @@ -190,9 +190,9 @@ public unsafe class Compressor : IDisposable fixed (ZSTD_outBuffer_s* outputPtr = &output) { using var cctx = handle.Acquire(); - return Unsafe.Methods - .ZSTD_compressStream2(cctx, outputPtr, inputPtr, directive) - .EnsureZstdSuccess(); + return Unsafe + .Methods.ZSTD_compressStream2(cctx, outputPtr, inputPtr, directive) + .EnsureZstdSuccess(); } } diff --git a/src/SharpCompress/Compressors/ZStandard/Constants.cs b/src/SharpCompress/Compressors/ZStandard/Constants.cs index 12c57270..cce84fc0 100644 --- a/src/SharpCompress/Compressors/ZStandard/Constants.cs +++ b/src/SharpCompress/Compressors/ZStandard/Constants.cs @@ -5,4 +5,4 @@ internal class Constants //NOTE: https://docs.microsoft.com/en-us/dotnet/framework/configure-apps/file-schema/runtime/gcallowverylargeobjects-element#remarks //NOTE: https://github.com/dotnet/runtime/blob/v5.0.0-rtm.20519.4/src/libraries/System.Private.CoreLib/src/System/Array.cs#L27 public const ulong MaxByteArrayLength = 0x7FFFFFC7; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs b/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs index 583acd01..9864a805 100644 --- a/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs +++ b/src/SharpCompress/Compressors/ZStandard/DecompressionStream.cs @@ -53,13 +53,11 @@ public class DecompressionStream : Stream this.checkEndOfStream = checkEndOfStream; inputBufferSize = - bufferSize > 0 ? bufferSize : (int)Unsafe.Methods.ZSTD_DStreamInSize().EnsureZstdSuccess(); + bufferSize > 0 + ? bufferSize + : (int)Unsafe.Methods.ZSTD_DStreamInSize().EnsureZstdSuccess(); inputBuffer = ArrayPool.Shared.Rent(inputBufferSize); - input = new ZSTD_inBuffer_s - { - pos = (nuint)inputBufferSize, - size = (nuint)inputBufferSize, - }; + input = new ZSTD_inBuffer_s { pos = (nuint)inputBufferSize, size = (nuint)inputBufferSize }; } public void SetParameter(ZSTD_dParameter parameter, int value) @@ -110,7 +108,7 @@ public class DecompressionStream : Stream #if !NETSTANDARD2_0 && !NETFRAMEWORK public override int Read(Span buffer) #else - public int Read(Span buffer) + public int Read(Span buffer) #endif { EnsureNotDisposed(); @@ -174,17 +172,17 @@ public class DecompressionStream : Stream ) #else - public override Task ReadAsync( - byte[] buffer, - int offset, - int count, - CancellationToken cancellationToken - ) => ReadAsync(new Memory(buffer, offset, count), cancellationToken); + public override Task ReadAsync( + byte[] buffer, + int offset, + int count, + CancellationToken cancellationToken + ) => ReadAsync(new Memory(buffer, offset, count), cancellationToken); - public async Task ReadAsync( - Memory buffer, - CancellationToken cancellationToken = default - ) + public async Task ReadAsync( + Memory buffer, + CancellationToken cancellationToken = default + ) #endif { EnsureNotDisposed(); @@ -222,8 +220,8 @@ public class DecompressionStream : Stream if ( ( bytesRead = await innerStream - .ReadAsync(inputBuffer, 0, inputBufferSize, cancellationToken) - .ConfigureAwait(false) + .ReadAsync(inputBuffer, 0, inputBufferSize, cancellationToken) + .ConfigureAwait(false) ) == 0 ) { @@ -265,8 +263,7 @@ public class DecompressionStream : Stream public override void Flush() => throw new NotSupportedException(); - public override long Seek(long offset, SeekOrigin origin) => - throw new NotSupportedException(); + public override long Seek(long offset, SeekOrigin origin) => throw new NotSupportedException(); public override void SetLength(long value) => throw new NotSupportedException(); @@ -280,17 +277,17 @@ public class DecompressionStream : Stream } #if NETSTANDARD2_0 || NETFRAMEWORK - public virtual Task DisposeAsync() + public virtual Task DisposeAsync() + { + try { - try - { - Dispose(); - return Task.CompletedTask; - } - catch (Exception exc) - { - return Task.FromException(exc); - } + Dispose(); + return Task.CompletedTask; } + catch (Exception exc) + { + return Task.FromException(exc); + } + } #endif } diff --git a/src/SharpCompress/Compressors/ZStandard/Decompressor.cs b/src/SharpCompress/Compressors/ZStandard/Decompressor.cs index 80fa8851..8a63c4d9 100644 --- a/src/SharpCompress/Compressors/ZStandard/Decompressor.cs +++ b/src/SharpCompress/Compressors/ZStandard/Decompressor.cs @@ -36,17 +36,17 @@ public unsafe class Decompressor : IDisposable { using var dctx = handle.Acquire(); fixed (byte* dictPtr = dict) - Unsafe.Methods - .ZSTD_DCtx_loadDictionary(dctx, dictPtr, (nuint)dict.Length) - .EnsureZstdSuccess(); + Unsafe + .Methods.ZSTD_DCtx_loadDictionary(dctx, dictPtr, (nuint)dict.Length) + .EnsureZstdSuccess(); } public static ulong GetDecompressedSize(ReadOnlySpan src) { fixed (byte* srcPtr = src) - return Unsafe.Methods - .ZSTD_decompressBound(srcPtr, (nuint)src.Length) - .EnsureContentSizeOk(); + return Unsafe + .Methods.ZSTD_decompressBound(srcPtr, (nuint)src.Length) + .EnsureContentSizeOk(); } public static ulong GetDecompressedSize(ArraySegment src) => @@ -84,15 +84,15 @@ public unsafe class Decompressor : IDisposable { using var dctx = handle.Acquire(); return (int) - Unsafe.Methods - .ZSTD_decompressDCtx( - dctx, - destPtr, - (nuint)dest.Length, - srcPtr, - (nuint)src.Length - ) - .EnsureZstdSuccess(); + Unsafe + .Methods.ZSTD_decompressDCtx( + dctx, + destPtr, + (nuint)dest.Length, + srcPtr, + (nuint)src.Length + ) + .EnsureZstdSuccess(); } } @@ -168,7 +168,9 @@ public unsafe class Decompressor : IDisposable fixed (ZSTD_outBuffer_s* outputPtr = &output) { using var dctx = handle.Acquire(); - return Unsafe.Methods.ZSTD_decompressStream(dctx, outputPtr, inputPtr).EnsureZstdSuccess(); + return Unsafe + .Methods.ZSTD_decompressStream(dctx, outputPtr, inputPtr) + .EnsureZstdSuccess(); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/SafeHandles.cs b/src/SharpCompress/Compressors/ZStandard/SafeHandles.cs index 4490274c..3b49bdce 100644 --- a/src/SharpCompress/Compressors/ZStandard/SafeHandles.cs +++ b/src/SharpCompress/Compressors/ZStandard/SafeHandles.cs @@ -47,10 +47,7 @@ internal sealed unsafe class SafeCctxHandle : SafeZstdHandle { var cctx = Unsafe.Methods.ZSTD_createCCtx(); if (cctx == null) - throw new ZstdException( - ZSTD_ErrorCode.ZSTD_error_GENERIC, - "Failed to create cctx" - ); + throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Failed to create cctx"); safeHandle.SetHandle((IntPtr)cctx); success = true; } @@ -100,10 +97,7 @@ internal sealed unsafe class SafeDctxHandle : SafeZstdHandle { var dctx = Unsafe.Methods.ZSTD_createDCtx(); if (dctx == null) - throw new ZstdException( - ZSTD_ErrorCode.ZSTD_error_GENERIC, - "Failed to create dctx" - ); + throw new ZstdException(ZSTD_ErrorCode.ZSTD_error_GENERIC, "Failed to create dctx"); safeHandle.SetHandle((IntPtr)dctx); success = true; } diff --git a/src/SharpCompress/Compressors/ZStandard/SynchronizationWrapper.cs b/src/SharpCompress/Compressors/ZStandard/SynchronizationWrapper.cs index e2f7894d..406cacd4 100644 --- a/src/SharpCompress/Compressors/ZStandard/SynchronizationWrapper.cs +++ b/src/SharpCompress/Compressors/ZStandard/SynchronizationWrapper.cs @@ -19,4 +19,4 @@ internal static unsafe class SynchronizationWrapper public static void PulseAll(void** obj) => Monitor.PulseAll(UnwrapObject(obj)); public static void Wait(void** mutex) => Monitor.Wait(UnwrapObject(mutex)); -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_CStream_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_CStream_t.cs index b8ef82f3..ab23c39a 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_CStream_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_CStream_t.cs @@ -11,4 +11,4 @@ public unsafe struct BIT_CStream_t public sbyte* startPtr; public sbyte* ptr; public sbyte* endPtr; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_DStream_status.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_DStream_status.cs index 4c0b1506..60b468b1 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_DStream_status.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/BIT_DStream_status.cs @@ -13,4 +13,4 @@ public enum BIT_DStream_status /* user requested more bits than present in bitstream */ BIT_DStream_overflow = 3, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Bitstream.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Bitstream.cs index d95e9076..88302a49 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Bitstream.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Bitstream.cs @@ -1,57 +1,57 @@ using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using static SharpCompress.Compressors.ZStandard.UnsafeHelper; #if NETCOREAPP3_0_OR_GREATER using System.Runtime.Intrinsics.X86; #endif -using static SharpCompress.Compressors.ZStandard.UnsafeHelper; namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_BIT_mask => - new uint[32] - { - 0, - 1, - 3, - 7, - 0xF, - 0x1F, - 0x3F, - 0x7F, - 0xFF, - 0x1FF, - 0x3FF, - 0x7FF, - 0xFFF, - 0x1FFF, - 0x3FFF, - 0x7FFF, - 0xFFFF, - 0x1FFFF, - 0x3FFFF, - 0x7FFFF, - 0xFFFFF, - 0x1FFFFF, - 0x3FFFFF, - 0x7FFFFF, - 0xFFFFFF, - 0x1FFFFFF, - 0x3FFFFFF, - 0x7FFFFFF, - 0xFFFFFFF, - 0x1FFFFFFF, - 0x3FFFFFFF, - 0x7FFFFFFF, - }; - private static uint* BIT_mask => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_BIT_mask) - ); + private static ReadOnlySpan Span_BIT_mask => + new uint[32] + { + 0, + 1, + 3, + 7, + 0xF, + 0x1F, + 0x3F, + 0x7F, + 0xFF, + 0x1FF, + 0x3FF, + 0x7FF, + 0xFFF, + 0x1FFF, + 0x3FFF, + 0x7FFF, + 0xFFFF, + 0x1FFFF, + 0x3FFFF, + 0x7FFFF, + 0xFFFFF, + 0x1FFFFF, + 0x3FFFFF, + 0x7FFFFF, + 0xFFFFFF, + 0x1FFFFFF, + 0x3FFFFFF, + 0x7FFFFFF, + 0xFFFFFFF, + 0x1FFFFFFF, + 0x3FFFFFFF, + 0x7FFFFFFF, + }; + private static uint* BIT_mask => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_BIT_mask) + ); #else private static readonly uint* BIT_mask = GetArrayPointer( @@ -100,11 +100,7 @@ public static unsafe partial class Methods * @return : 0 if success, * otherwise an error code (can be tested using ERR_isError()) */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static nuint BIT_initCStream( - ref BIT_CStream_t bitC, - void* startPtr, - nuint dstCapacity - ) + private static nuint BIT_initCStream(ref BIT_CStream_t bitC, void* startPtr, nuint dstCapacity) { bitC.bitContainer = 0; bitC.bitPos = 0; @@ -121,15 +117,15 @@ public static unsafe partial class Methods { assert(nbBits < sizeof(uint) * 32 / sizeof(uint)); #if NETCOREAPP3_1_OR_GREATER - if (Bmi2.X64.IsSupported) - { - return (nuint)Bmi2.X64.ZeroHighBits(bitContainer, nbBits); - } + if (Bmi2.X64.IsSupported) + { + return (nuint)Bmi2.X64.ZeroHighBits(bitContainer, nbBits); + } - if (Bmi2.IsSupported) - { - return Bmi2.ZeroHighBits((uint)bitContainer, nbBits); - } + if (Bmi2.IsSupported) + { + return Bmi2.ZeroHighBits((uint)bitContainer, nbBits); + } #endif return bitContainer & BIT_mask[nbBits]; @@ -270,16 +266,13 @@ public static unsafe partial class Methods switch (srcSize) { case 7: - bitD->bitContainer += - (nuint)((byte*)srcBuffer)[6] << sizeof(nuint) * 8 - 16; + bitD->bitContainer += (nuint)((byte*)srcBuffer)[6] << sizeof(nuint) * 8 - 16; goto case 6; case 6: - bitD->bitContainer += - (nuint)((byte*)srcBuffer)[5] << sizeof(nuint) * 8 - 24; + bitD->bitContainer += (nuint)((byte*)srcBuffer)[5] << sizeof(nuint) * 8 - 24; goto case 5; case 5: - bitD->bitContainer += - (nuint)((byte*)srcBuffer)[4] << sizeof(nuint) * 8 - 32; + bitD->bitContainer += (nuint)((byte*)srcBuffer)[4] << sizeof(nuint) * 8 - 32; goto case 4; case 4: bitD->bitContainer += (nuint)((byte*)srcBuffer)[3] << 24; @@ -298,9 +291,7 @@ public static unsafe partial class Methods byte lastByte = ((byte*)srcBuffer)[srcSize - 1]; bitD->bitsConsumed = lastByte != 0 ? 8 - ZSTD_highbit32(lastByte) : 0; if (lastByte == 0) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } bitD->bitsConsumed += (uint)((nuint)sizeof(nuint) - srcSize) * 8; @@ -321,15 +312,15 @@ public static unsafe partial class Methods uint regMask = (uint)(sizeof(nuint) * 8 - 1); assert(nbBits < sizeof(uint) * 32 / sizeof(uint)); #if NETCOREAPP3_1_OR_GREATER - if (Bmi2.X64.IsSupported) - { - return (nuint)Bmi2.X64.ZeroHighBits(bitContainer >> (int)(start & regMask), nbBits); - } + if (Bmi2.X64.IsSupported) + { + return (nuint)Bmi2.X64.ZeroHighBits(bitContainer >> (int)(start & regMask), nbBits); + } - if (Bmi2.IsSupported) - { - return Bmi2.ZeroHighBits((uint)(bitContainer >> (int)(start & regMask)), nbBits); - } + if (Bmi2.IsSupported) + { + return Bmi2.ZeroHighBits((uint)(bitContainer >> (int)(start & regMask)), nbBits); + } #endif return (nuint)(bitContainer >> (int)(start & regMask) & ((ulong)1 << (int)nbBits) - 1); @@ -359,8 +350,8 @@ public static unsafe partial class Methods uint regMask = (uint)(sizeof(nuint) * 8 - 1); assert(nbBits >= 1); return bitD->bitContainer - << (int)(bitD->bitsConsumed & regMask) - >> (int)(regMask + 1 - nbBits & regMask); + << (int)(bitD->bitsConsumed & regMask) + >> (int)(regMask + 1 - nbBits & regMask); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -423,13 +414,13 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_static_zeroFilled => - new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; - private static nuint* static_zeroFilled => - (nuint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_static_zeroFilled) - ); + private static ReadOnlySpan Span_static_zeroFilled => + new byte[] { 0, 0, 0, 0, 0, 0, 0, 0 }; + private static nuint* static_zeroFilled => + (nuint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_static_zeroFilled) + ); #else private static readonly nuint* static_zeroFilled = (nuint*)GetArrayPointer( @@ -485,10 +476,9 @@ public static unsafe partial class Methods [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint BIT_endOfDStream(BIT_DStream_t* DStream) { - return - DStream->ptr == DStream->start && DStream->bitsConsumed == (uint)(sizeof(nuint) * 8) - ? 1U - : 0U; + return DStream->ptr == DStream->start && DStream->bitsConsumed == (uint)(sizeof(nuint) * 8) + ? 1U + : 0U; } /*-******************************************************** @@ -554,9 +544,7 @@ public static unsafe partial class Methods byte lastByte = ((byte*)srcBuffer)[srcSize - 1]; bitD.bitsConsumed = lastByte != 0 ? 8 - ZSTD_highbit32(lastByte) : 0; if (lastByte == 0) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } bitD.bitsConsumed += (uint)((nuint)sizeof(nuint) - srcSize) * 8; @@ -572,11 +560,7 @@ public static unsafe partial class Methods * On 64-bits, maxNbBits==56. * @return : value extracted */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static nuint BIT_lookBits( - nuint bitD_bitContainer, - uint bitD_bitsConsumed, - uint nbBits - ) + private static nuint BIT_lookBits(nuint bitD_bitContainer, uint bitD_bitsConsumed, uint nbBits) { return BIT_getMiddleBits( bitD_bitContainer, @@ -597,8 +581,8 @@ public static unsafe partial class Methods uint regMask = (uint)(sizeof(nuint) * 8 - 1); assert(nbBits >= 1); return bitD_bitContainer - << (int)(bitD_bitsConsumed & regMask) - >> (int)(regMask + 1 - nbBits & regMask); + << (int)(bitD_bitsConsumed & regMask) + >> (int)(regMask + 1 - nbBits & regMask); } [MethodImpl(MethodImplOptions.AggressiveInlining)] diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/BlockSummary.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/BlockSummary.cs index 46f1d706..9a53651d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/BlockSummary.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/BlockSummary.cs @@ -5,4 +5,4 @@ public struct BlockSummary public nuint nbSequences; public nuint blockSize; public nuint litSize; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_best_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_best_s.cs index 1c56883a..38083132 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_best_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_best_s.cs @@ -17,4 +17,4 @@ public unsafe struct COVER_best_s public nuint dictSize; public ZDICT_cover_params_t parameters; public nuint compressedSize; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_ctx_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_ctx_t.cs index 839d3735..28712762 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_ctx_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_ctx_t.cs @@ -16,4 +16,4 @@ public unsafe struct COVER_ctx_t public uint* freqs; public uint* dmerAt; public uint d; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_map_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_map_s.cs index 7c7d29d7..dbfa337f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_map_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_map_s.cs @@ -6,4 +6,4 @@ public unsafe struct COVER_map_s public uint sizeLog; public uint size; public uint sizeMask; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_segment_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_segment_t.cs index bc6be3ec..7e852ea9 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_segment_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/COVER_segment_t.cs @@ -8,4 +8,4 @@ public struct COVER_segment_t public uint begin; public uint end; public uint score; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Cover.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Cover.cs index a199a19d..11c79f3c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Cover.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Cover.cs @@ -24,11 +24,7 @@ public static unsafe partial class Methods /** * Warns the user when their corpus is too small. */ - private static void COVER_warnOnSmallCorpus( - nuint maxDictSize, - nuint nbDmers, - int displayLevel - ) + private static void COVER_warnOnSmallCorpus(nuint maxDictSize, nuint nbDmers, int displayLevel) { double ratio = nbDmers / (double)maxDictSize; if (ratio >= 10) @@ -100,8 +96,7 @@ public static unsafe partial class Methods i = parameters.splitPoint < 1 ? nbTrainSamples : 0; for (; i < nbSamples; ++i) { - maxSampleSize = - samplesSizes[i] > maxSampleSize ? samplesSizes[i] : maxSampleSize; + maxSampleSize = samplesSizes[i] > maxSampleSize ? samplesSizes[i] : maxSampleSize; } dstCapacity = ZSTD_compressBound(maxSampleSize); @@ -435,11 +430,7 @@ public static unsafe partial class Methods if (totalCompressedSize <= largestCompressed * regressionTolerance) { free(largestDictbuffer); - return setDictSelection( - candidateDictBuffer, - dictContentSize, - totalCompressedSize - ); + return setDictSelection(candidateDictBuffer, dictContentSize, totalCompressedSize); } dictContentSize *= 2; @@ -450,4 +441,4 @@ public static unsafe partial class Methods free(candidateDictBuffer); return setDictSelection(largestDictbuffer, dictContentSize, totalCompressedSize); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/DTableDesc.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/DTableDesc.cs index c89de564..6586ac46 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/DTableDesc.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/DTableDesc.cs @@ -9,4 +9,4 @@ public struct DTableDesc public byte tableType; public byte tableLog; public byte reserved; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/EStats_ress_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/EStats_ress_t.cs index 93d18c38..9d3f1ba2 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/EStats_ress_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/EStats_ress_t.cs @@ -10,4 +10,4 @@ public unsafe struct EStats_ress_t /* must be ZSTD_BLOCKSIZE_MAX allocated */ public void* workPlace; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/EntropyCommon.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/EntropyCommon.cs index 77283d84..e14f925f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/EntropyCommon.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/EntropyCommon.cs @@ -73,9 +73,7 @@ public static unsafe partial class Methods if (FSE_isError(countSize)) return countSize; if (countSize > hbSize) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); return countSize; } } @@ -220,13 +218,7 @@ public static unsafe partial class Methods nuint hbSize ) { - return FSE_readNCount_body( - normalizedCounter, - maxSVPtr, - tableLogPtr, - headerBuffer, - hbSize - ); + return FSE_readNCount_body(normalizedCounter, maxSVPtr, tableLogPtr, headerBuffer, hbSize); } /*! FSE_readNCount_bmi2(): @@ -369,9 +361,7 @@ public static unsafe partial class Methods for (n = 0; n < oSize; n++) { if (huffWeight[n] > 12) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); rankStats[huffWeight[n]]++; weightTotal += (uint)(1 << huffWeight[n] >> 1); } @@ -390,9 +380,7 @@ public static unsafe partial class Methods uint verif = (uint)(1 << (int)ZSTD_highbit32(rest)); uint lastWeight = ZSTD_highbit32(rest) + 1; if (verif != rest) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); huffWeight[oSize] = (byte)lastWeight; rankStats[lastWeight]++; } diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/EstimatedBlockSize.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/EstimatedBlockSize.cs index a1718372..a2f59adc 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/EstimatedBlockSize.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/EstimatedBlockSize.cs @@ -4,4 +4,4 @@ public struct EstimatedBlockSize { public nuint estLitSize; public nuint estBlockSize; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_ctx_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_ctx_t.cs index d404ccc0..8c79a30d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_ctx_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_ctx_t.cs @@ -16,4 +16,4 @@ public unsafe struct FASTCOVER_ctx_t public uint d; public uint f; public FASTCOVER_accel_t accelParams; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_tryParameters_data_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_tryParameters_data_s.cs index b166fe45..3a6e14f0 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_tryParameters_data_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FASTCOVER_tryParameters_data_s.cs @@ -9,4 +9,4 @@ public unsafe struct FASTCOVER_tryParameters_data_s public COVER_best_s* best; public nuint dictBufferCapacity; public ZDICT_cover_params_t parameters; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DTableHeader.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DTableHeader.cs index ae6269ec..db091f0c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DTableHeader.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DTableHeader.cs @@ -5,4 +5,4 @@ public struct FSE_DTableHeader { public ushort tableLog; public ushort fastMode; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DecompressWksp.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DecompressWksp.cs index 3ecda2bc..cd03c36f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DecompressWksp.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FSE_DecompressWksp.cs @@ -3,4 +3,4 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public unsafe struct FSE_DecompressWksp { public fixed short ncount[256]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Fastcover.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Fastcover.cs index ed6f0912..2bd7e30c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Fastcover.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Fastcover.cs @@ -20,23 +20,22 @@ public static unsafe partial class Methods return ZSTD_hash8Ptr(p, f); } - private static readonly FASTCOVER_accel_t* FASTCOVER_defaultAccelParameters = - GetArrayPointer( - new FASTCOVER_accel_t[11] - { - new FASTCOVER_accel_t(finalize: 100, skip: 0), - new FASTCOVER_accel_t(finalize: 100, skip: 0), - new FASTCOVER_accel_t(finalize: 50, skip: 1), - new FASTCOVER_accel_t(finalize: 34, skip: 2), - new FASTCOVER_accel_t(finalize: 25, skip: 3), - new FASTCOVER_accel_t(finalize: 20, skip: 4), - new FASTCOVER_accel_t(finalize: 17, skip: 5), - new FASTCOVER_accel_t(finalize: 14, skip: 6), - new FASTCOVER_accel_t(finalize: 13, skip: 7), - new FASTCOVER_accel_t(finalize: 11, skip: 8), - new FASTCOVER_accel_t(finalize: 10, skip: 9), - } - ); + private static readonly FASTCOVER_accel_t* FASTCOVER_defaultAccelParameters = GetArrayPointer( + new FASTCOVER_accel_t[11] + { + new FASTCOVER_accel_t(finalize: 100, skip: 0), + new FASTCOVER_accel_t(finalize: 100, skip: 0), + new FASTCOVER_accel_t(finalize: 50, skip: 1), + new FASTCOVER_accel_t(finalize: 34, skip: 2), + new FASTCOVER_accel_t(finalize: 25, skip: 3), + new FASTCOVER_accel_t(finalize: 20, skip: 4), + new FASTCOVER_accel_t(finalize: 17, skip: 5), + new FASTCOVER_accel_t(finalize: 14, skip: 6), + new FASTCOVER_accel_t(finalize: 13, skip: 7), + new FASTCOVER_accel_t(finalize: 11, skip: 8), + new FASTCOVER_accel_t(finalize: 10, skip: 9), + } + ); /*-************************************* * Helper functions @@ -91,11 +90,7 @@ public static unsafe partial class Methods if (activeSegment.end - activeSegment.begin == dmersInK + 1) { /* Get hash value of the dmer to be eliminated from active segment */ - nuint delIndex = FASTCOVER_hashPtrToIndex( - ctx->samples + activeSegment.begin, - f, - d - ); + nuint delIndex = FASTCOVER_hashPtrToIndex(ctx->samples + activeSegment.begin, f, d); segmentFreqs[delIndex] -= 1; if (segmentFreqs[delIndex] == 0) { @@ -403,9 +398,7 @@ public static unsafe partial class Methods parameters, segmentFreqs ); - uint nbFinalizeSamples = (uint)( - ctx->nbTrainSamples * ctx->accelParams.finalize / 100 - ); + uint nbFinalizeSamples = (uint)(ctx->nbTrainSamples * ctx->accelParams.finalize / 100); selection = COVER_selectDict( dict + tail, dictBufferCapacity, @@ -544,10 +537,7 @@ public static unsafe partial class Methods COVER_warnOnSmallCorpus(dictBufferCapacity, ctx.nbDmers, g_displayLevel); { /* Initialize array to keep track of frequency of dmer within activeSegment */ - ushort* segmentFreqs = (ushort*)calloc( - (ulong)1 << (int)parameters.f, - sizeof(ushort) - ); + ushort* segmentFreqs = (ushort*)calloc((ulong)1 << (int)parameters.f, sizeof(ushort)); nuint tail = FASTCOVER_buildDictionary( &ctx, ctx.freqs, @@ -556,9 +546,7 @@ public static unsafe partial class Methods coverParams, segmentFreqs ); - uint nbFinalizeSamples = (uint)( - ctx.nbTrainSamples * ctx.accelParams.finalize / 100 - ); + uint nbFinalizeSamples = (uint)(ctx.nbTrainSamples * ctx.accelParams.finalize / 100); nuint dictionarySize = ZDICT_finalizeDictionary( dict, dictBufferCapacity, @@ -706,9 +694,7 @@ public static unsafe partial class Methods COVER_best_destroy(&best); FASTCOVER_ctx_destroy(&ctx); POOL_free(pool); - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); } data->ctx = &ctx; diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Fse.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Fse.cs index 05e4b30a..32798dfe 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Fse.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Fse.cs @@ -51,9 +51,7 @@ public static unsafe partial class Methods ushort* stateTable = (ushort*)statePtr.stateTable; uint nbBitsOut = (uint)statePtr.value + symbolTT.deltaNbBits >> 16; BIT_addBits(ref bitC_bitContainer, ref bitC_bitPos, (nuint)statePtr.value, nbBitsOut); - statePtr.value = stateTable[ - (statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState - ]; + statePtr.value = stateTable[(statePtr.value >> (int)nbBitsOut) + symbolTT.deltaFindState]; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -105,8 +103,7 @@ public static unsafe partial class Methods assert(accuracyLog < 31 - tableLog); { uint tableSize = (uint)(1 << (int)tableLog); - uint deltaFromThreshold = - threshold - (symbolTT[symbolValue].deltaNbBits + tableSize); + uint deltaFromThreshold = threshold - (symbolTT[symbolValue].deltaNbBits + tableSize); /* linear interpolation (very approximate) */ uint normalizedDeltaFromThreshold = deltaFromThreshold << (int)accuracyLog >> (int)tableLog; @@ -118,19 +115,11 @@ public static unsafe partial class Methods } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void FSE_initDState( - ref FSE_DState_t DStatePtr, - ref BIT_DStream_t bitD, - uint* dt - ) + private static void FSE_initDState(ref FSE_DState_t DStatePtr, ref BIT_DStream_t bitD, uint* dt) { void* ptr = dt; FSE_DTableHeader* DTableH = (FSE_DTableHeader*)ptr; - DStatePtr.state = BIT_readBits( - bitD.bitContainer, - ref bitD.bitsConsumed, - DTableH->tableLog - ); + DStatePtr.state = BIT_readBits(bitD.bitContainer, ref bitD.bitsConsumed, DTableH->tableLog); BIT_reloadDStream( ref bitD.bitContainer, ref bitD.bitsConsumed, @@ -206,4 +195,4 @@ public static unsafe partial class Methods statePtr.symbolTT = ct + 1 + (tableLog != 0 ? 1 << (int)(tableLog - 1) : 1); statePtr.stateLog = tableLog; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FseCompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FseCompress.cs index abe85537..c4c763a1 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FseCompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FseCompress.cs @@ -37,10 +37,7 @@ public static unsafe partial class Methods assert(((nuint)workSpace & 1) == 0); if ( sizeof(uint) - * ( - (maxSymbolValue + 2 + (1UL << (int)tableLog)) / 2 - + sizeof(ulong) / sizeof(uint) - ) + * ((maxSymbolValue + 2 + (1UL << (int)tableLog)) / 2 + sizeof(ulong) / sizeof(uint)) > wkspSize ) return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge)); @@ -151,8 +148,7 @@ public static unsafe partial class Methods switch (normalizedCounter[s]) { case 0: - symbolTT[s].deltaNbBits = - (tableLog + 1 << 16) - (uint)(1 << (int)tableLog); + symbolTT[s].deltaNbBits = (tableLog + 1 << 16) - (uint)(1 << (int)tableLog); break; case -1: case 1: @@ -164,16 +160,14 @@ public static unsafe partial class Methods default: assert(normalizedCounter[s] > 1); - { - uint maxBitsOut = - tableLog - ZSTD_highbit32((uint)normalizedCounter[s] - 1); - uint minStatePlus = (uint)normalizedCounter[s] << (int)maxBitsOut; - symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus; - symbolTT[s].deltaFindState = (int)( - total - (uint)normalizedCounter[s] - ); - total += (uint)normalizedCounter[s]; - } + { + uint maxBitsOut = + tableLog - ZSTD_highbit32((uint)normalizedCounter[s] - 1); + uint minStatePlus = (uint)normalizedCounter[s] << (int)maxBitsOut; + symbolTT[s].deltaNbBits = (maxBitsOut << 16) - minStatePlus; + symbolTT[s].deltaFindState = (int)(total - (uint)normalizedCounter[s]); + total += (uint)normalizedCounter[s]; + } break; } @@ -232,9 +226,7 @@ public static unsafe partial class Methods start += 24; bitStream += 0xFFFFU << bitCount; if (writeIsSafe == 0 && @out > oend - 2) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); @out[0] = (byte)bitStream; @out[1] = (byte)(bitStream >> 8); @out += 2; @@ -253,9 +245,7 @@ public static unsafe partial class Methods if (bitCount > 16) { if (writeIsSafe == 0 && @out > oend - 2) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); @out[0] = (byte)bitStream; @out[1] = (byte)(bitStream >> 8); @out += 2; @@ -384,11 +374,7 @@ public static unsafe partial class Methods dynamically downsize 'tableLog' when conditions are met. It saves CPU time, by using smaller tables, while preserving or even improving compression ratio. @return : recommended tableLog (necessarily <= 'maxTableLog') */ - private static uint FSE_optimalTableLog( - uint maxTableLog, - nuint srcSize, - uint maxSymbolValue - ) + private static uint FSE_optimalTableLog(uint maxTableLog, nuint srcSize, uint maxSymbolValue) { return FSE_optimalTableLog_internal(maxTableLog, srcSize, maxSymbolValue, 2); } @@ -464,7 +450,7 @@ public static unsafe partial class Methods probably incompressible data (should have already been detected); find max, then give all remaining points to max */ uint maxV = 0, - maxC = 0; + maxC = 0; for (s = 0; s <= maxSymbolValue; s++) if (count[s] > maxC) { @@ -514,13 +500,13 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_rtbTable => - new uint[8] { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 }; - private static uint* rtbTable => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_rtbTable) - ); + private static ReadOnlySpan Span_rtbTable => + new uint[8] { 0, 473195, 504333, 520860, 550000, 700000, 750000, 830000 }; + private static uint* rtbTable => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_rtbTable) + ); #else private static readonly uint* rtbTable = GetArrayPointer( @@ -655,7 +641,7 @@ public static unsafe partial class Methods BIT_CStream_t bitC; System.Runtime.CompilerServices.Unsafe.SkipInit(out bitC); FSE_CState_t CState1, - CState2; + CState2; System.Runtime.CompilerServices.Unsafe.SkipInit(out CState1); System.Runtime.CompilerServices.Unsafe.SkipInit(out CState2); if (srcSize <= 2) @@ -683,12 +669,7 @@ public static unsafe partial class Methods bitC_endPtr ); else - BIT_flushBits( - ref bitC_bitContainer, - ref bitC_bitPos, - ref bitC_ptr, - bitC_endPtr - ); + BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr); } else { @@ -709,12 +690,7 @@ public static unsafe partial class Methods bitC_endPtr ); else - BIT_flushBits( - ref bitC_bitContainer, - ref bitC_bitPos, - ref bitC_ptr, - bitC_endPtr - ); + BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr); } while (ip > istart) @@ -750,12 +726,7 @@ public static unsafe partial class Methods bitC_endPtr ); else - BIT_flushBits( - ref bitC_bitContainer, - ref bitC_bitPos, - ref bitC_ptr, - bitC_endPtr - ); + BIT_flushBits(ref bitC_bitContainer, ref bitC_bitPos, ref bitC_ptr, bitC_endPtr); } FSE_flushCState( diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/FseDecompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/FseDecompress.cs index e869c575..12be4ef6 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/FseDecompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/FseDecompress.cs @@ -102,7 +102,7 @@ public static unsafe partial class Methods uint tableMask = tableSize - 1; uint step = (tableSize >> 1) + (tableSize >> 3) + 3; uint s, - position = 0; + position = 0; for (s = 0; s < maxSV1; s++) { int i; @@ -213,7 +213,7 @@ public static unsafe partial class Methods bitD_start, bitD_limitPtr ) == BIT_DStream_status.BIT_DStream_unfinished - && op < olimit; + && op < olimit; op += 4 ) { @@ -288,16 +288,8 @@ public static unsafe partial class Methods { *op++ = fast != 0 - ? FSE_decodeSymbolFast( - ref state2, - bitD_bitContainer, - ref bitD_bitsConsumed - ) - : FSE_decodeSymbol( - ref state2, - bitD_bitContainer, - ref bitD_bitsConsumed - ); + ? FSE_decodeSymbolFast(ref state2, bitD_bitContainer, ref bitD_bitsConsumed) + : FSE_decodeSymbol(ref state2, bitD_bitContainer, ref bitD_bitsConsumed); break; } @@ -319,16 +311,8 @@ public static unsafe partial class Methods { *op++ = fast != 0 - ? FSE_decodeSymbolFast( - ref state1, - bitD_bitContainer, - ref bitD_bitsConsumed - ) - : FSE_decodeSymbol( - ref state1, - bitD_bitContainer, - ref bitD_bitsConsumed - ); + ? FSE_decodeSymbolFast(ref state1, bitD_bitContainer, ref bitD_bitsConsumed) + : FSE_decodeSymbol(ref state1, bitD_bitContainer, ref bitD_bitsConsumed); break; } } @@ -394,15 +378,13 @@ public static unsafe partial class Methods return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_tableLog_tooLarge)); assert( (nuint)(sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint)) - <= wkspSize + <= wkspSize ); workSpace = (byte*)workSpace + sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint); - wkspSize -= (nuint)( - sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint) - ); + wkspSize -= (nuint)(sizeof(FSE_DecompressWksp) + (1 + (1 << (int)tableLog)) * sizeof(uint)); { nuint _var_err__ = FSE_buildDTable_internal( dtable, @@ -429,14 +411,7 @@ public static unsafe partial class Methods dtable, 1 ); - return FSE_decompress_usingDTable_generic( - dst, - dstCapacity, - ip, - cSrcSize, - dtable, - 0 - ); + return FSE_decompress_usingDTable_generic(dst, dstCapacity, ip, cSrcSize, dtable, 0); } } @@ -484,4 +459,4 @@ public static unsafe partial class Methods wkspSize ); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HIST_checkInput_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HIST_checkInput_e.cs index c3a8a82b..8aca6e8f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HIST_checkInput_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HIST_checkInput_e.cs @@ -4,4 +4,4 @@ public enum HIST_checkInput_e { trustInput, checkMaxSymbolValue, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_CompressWeightsWksp.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_CompressWeightsWksp.cs index 2ee9b03a..789f4e7f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_CompressWeightsWksp.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_CompressWeightsWksp.cs @@ -6,4 +6,4 @@ public unsafe struct HUF_CompressWeightsWksp public fixed uint scratchBuffer[41]; public fixed uint count[13]; public fixed short norm[13]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_DecompressFastArgs.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_DecompressFastArgs.cs index ca170534..c9b8d2d5 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_DecompressFastArgs.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_DecompressFastArgs.cs @@ -46,4 +46,4 @@ public unsafe struct HUF_DecompressFastArgs public byte* e2; public byte* e3; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX1_Workspace.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX1_Workspace.cs index 5ba94164..529a3e5e 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX1_Workspace.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX1_Workspace.cs @@ -7,4 +7,4 @@ public unsafe struct HUF_ReadDTableX1_Workspace public fixed uint statsWksp[219]; public fixed byte symbols[256]; public fixed byte huffWeight[256]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX2_Workspace.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX2_Workspace.cs index 9d188e9b..a85bbb6c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX2_Workspace.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_ReadDTableX2_Workspace.cs @@ -12,11 +12,11 @@ public unsafe struct HUF_ReadDTableX2_Workspace public fixed uint calleeWksp[219]; #if NET8_0_OR_GREATER - [InlineArray(12)] - public unsafe struct _rankVal_e__FixedBuffer - { - public rankValCol_t e0; - } + [InlineArray(12)] + public unsafe struct _rankVal_e__FixedBuffer + { + public rankValCol_t e0; + } #else public unsafe struct _rankVal_e__FixedBuffer @@ -37,11 +37,11 @@ public unsafe struct HUF_ReadDTableX2_Workspace #endif #if NET8_0_OR_GREATER - [InlineArray(256)] - public unsafe struct _sortedSymbol_e__FixedBuffer - { - public sortedSymbol_t e0; - } + [InlineArray(256)] + public unsafe struct _sortedSymbol_e__FixedBuffer + { + public sortedSymbol_t e0; + } #else public unsafe struct _sortedSymbol_e__FixedBuffer diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_buildCTable_wksp_tables.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_buildCTable_wksp_tables.cs index 0fb8400a..4fe92db7 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_buildCTable_wksp_tables.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_buildCTable_wksp_tables.cs @@ -8,11 +8,11 @@ public struct HUF_buildCTable_wksp_tables public _rankPosition_e__FixedBuffer rankPosition; #if NET8_0_OR_GREATER - [InlineArray(512)] - public unsafe struct _huffNodeTbl_e__FixedBuffer - { - public nodeElt_s e0; - } + [InlineArray(512)] + public unsafe struct _huffNodeTbl_e__FixedBuffer + { + public nodeElt_s e0; + } #else public unsafe struct _huffNodeTbl_e__FixedBuffer @@ -533,11 +533,11 @@ public struct HUF_buildCTable_wksp_tables #endif #if NET8_0_OR_GREATER - [InlineArray(192)] - public unsafe struct _rankPosition_e__FixedBuffer - { - public rankPos e0; - } + [InlineArray(192)] + public unsafe struct _rankPosition_e__FixedBuffer + { + public rankPos e0; + } #else public unsafe struct _rankPosition_e__FixedBuffer @@ -736,4 +736,4 @@ public struct HUF_buildCTable_wksp_tables public rankPos e191; } #endif -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_compress_tables_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_compress_tables_t.cs index 4d8fde23..6e6e12c0 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_compress_tables_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HUF_compress_tables_t.cs @@ -9,11 +9,11 @@ public unsafe struct HUF_compress_tables_t public _wksps_e__Union wksps; #if NET8_0_OR_GREATER - [InlineArray(257)] - public unsafe struct _CTable_e__FixedBuffer - { - public nuint e0; - } + [InlineArray(257)] + public unsafe struct _CTable_e__FixedBuffer + { + public nuint e0; + } #else public unsafe struct _CTable_e__FixedBuffer diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Hist.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Hist.cs index 7f6a6bb1..10a433ce 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Hist.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Hist.cs @@ -157,9 +157,7 @@ public static unsafe partial class Methods while (Counting1[maxSymbolValue] == 0) maxSymbolValue--; if (check != default && maxSymbolValue > *maxSymbolValuePtr) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxSymbolValue_tooSmall)); *maxSymbolValuePtr = maxSymbolValue; memmove(count, Counting1, countSize); } @@ -260,12 +258,7 @@ public static unsafe partial class Methods * or an error code, which can be tested using HIST_isError(). * note : if return == srcSize, there is only one symbol. */ - private static nuint HIST_count( - uint* count, - uint* maxSymbolValuePtr, - void* src, - nuint srcSize - ) + private static nuint HIST_count(uint* count, uint* maxSymbolValuePtr, void* src, nuint srcSize) { uint* tmpCounters = stackalloc uint[1024]; return HIST_count_wksp( diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HufCompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HufCompress.cs index 9d00fb3e..785c8143 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HufCompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HufCompress.cs @@ -5,11 +5,7 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { - private static void* HUF_alignUpWorkspace( - void* workspace, - nuint* workspaceSizePtr, - nuint align - ) + private static void* HUF_alignUpWorkspace(void* workspace, nuint* workspaceSizePtr, nuint align) { nuint mask = align - 1; nuint rem = (nuint)workspace & mask; @@ -56,12 +52,7 @@ public static unsafe partial class Methods return 0; { /* never fails */ - uint maxCount = HIST_count_simple( - wksp->count, - &maxSymbolValue, - weightTable, - wtSize - ); + uint maxCount = HIST_count_simple(wksp->count, &maxSymbolValue, weightTable, wtSize); if (maxCount == wtSize) return 1; if (maxCount == 1) @@ -289,7 +280,7 @@ public static unsafe partial class Methods HUF_writeCTableHeader(CTable, tableLog, *maxSymbolValuePtr); { uint n, - nextRankStart = 0; + nextRankStart = 0; for (n = 1; n <= tableLog; n++) { uint curr = nextRankStart; @@ -377,11 +368,7 @@ public static unsafe partial class Methods * respect targetNbBits. * @return The maximum number of bits of the Huffman tree after adjustment. */ - private static uint HUF_setMaxHeight( - nodeElt_s* huffNode, - uint lastNonNull, - uint targetNbBits - ) + private static uint HUF_setMaxHeight(nodeElt_s* huffNode, uint lastNonNull, uint targetNbBits) { uint largestBits = huffNode[lastNonNull].nbBits; if (largestBits <= targetNbBits) @@ -392,9 +379,7 @@ public static unsafe partial class Methods int n = (int)lastNonNull; while (huffNode[n].nbBits > targetNbBits) { - totalCost += (int)( - baseCost - (uint)(1 << (int)(largestBits - huffNode[n].nbBits)) - ); + totalCost += (int)(baseCost - (uint)(1 << (int)(largestBits - huffNode[n].nbBits))); huffNode[n].nbBits = (byte)targetNbBits; n--; } @@ -753,11 +738,7 @@ public static unsafe partial class Methods ) { HUF_buildCTable_wksp_tables* wksp_tables = - (HUF_buildCTable_wksp_tables*)HUF_alignUpWorkspace( - workSpace, - &wkspSize, - sizeof(uint) - ); + (HUF_buildCTable_wksp_tables*)HUF_alignUpWorkspace(workSpace, &wkspSize, sizeof(uint)); nodeElt_s* huffNode0 = &wksp_tables->huffNodeTbl.e0; nodeElt_s* huffNode = huffNode0 + 1; int nonNullRank; @@ -777,11 +758,7 @@ public static unsafe partial class Methods return maxNbBits; } - private static nuint HUF_estimateCompressedSize( - nuint* CTable, - uint* count, - uint maxSymbolValue - ) + private static nuint HUF_estimateCompressedSize(nuint* CTable, uint* count, uint maxSymbolValue) { nuint* ct = CTable + 1; nuint nbBits = 0; @@ -820,11 +797,7 @@ public static unsafe partial class Methods * Initializes the bitstream. * @returns 0 or an error code. */ - private static nuint HUF_initCStream( - ref HUF_CStream_t bitC, - void* startPtr, - nuint dstCapacity - ) + private static nuint HUF_initCStream(ref HUF_CStream_t bitC, void* startPtr, nuint dstCapacity) { bitC = new HUF_CStream_t { @@ -937,13 +910,7 @@ public static unsafe partial class Methods private static nuint HUF_closeCStream(ref HUF_CStream_t bitC) { HUF_addBits(ref bitC.bitContainer.e0, ref bitC.bitPos.e0, HUF_endMark(), 0); - HUF_flushBits( - ref bitC.bitContainer.e0, - ref bitC.bitPos.e0, - ref bitC.ptr, - bitC.endPtr, - 0 - ); + HUF_flushBits(ref bitC.bitContainer.e0, ref bitC.bitPos.e0, ref bitC.ptr, bitC.endPtr, 0); { nuint nbBits = bitC.bitPos.e0 & 0xFF; if (bitC.ptr >= bitC.endPtr) @@ -1006,13 +973,7 @@ public static unsafe partial class Methods int u; for (u = 1; u < kUnroll; ++u) { - HUF_encodeSymbol( - ref bitC_bitContainer_e0, - ref bitC_bitPos_e0, - ip[n - u], - ct, - 1 - ); + HUF_encodeSymbol(ref bitC_bitContainer_e0, ref bitC_bitPos_e0, ip[n - u], ct, 1); } HUF_encodeSymbol( @@ -1039,13 +1000,7 @@ public static unsafe partial class Methods int u; for (u = 1; u < kUnroll; ++u) { - HUF_encodeSymbol( - ref bitC_bitContainer_e0, - ref bitC_bitPos_e0, - ip[n - u], - ct, - 1 - ); + HUF_encodeSymbol(ref bitC_bitContainer_e0, ref bitC_bitPos_e0, ip[n - u], ct, 1); } HUF_encodeSymbol( @@ -1511,12 +1466,12 @@ public static unsafe partial class Methods byte* dst = (byte*)workSpace + sizeof(HUF_WriteCTableWksp); nuint dstSize = wkspSize - (nuint)sizeof(HUF_WriteCTableWksp); nuint hSize, - newSize; + newSize; uint symbolCardinality = HUF_cardinality(count, maxSymbolValue); uint minTableLog = HUF_minTableLog(symbolCardinality); nuint optSize = unchecked((nuint)~0) - 1; uint optLog = maxTableLog, - optLogGuess; + optLogGuess; for (optLogGuess = minTableLog; optLogGuess <= maxTableLog; optLogGuess++) { { @@ -1623,10 +1578,7 @@ public static unsafe partial class Methods ); } - if ( - (flags & (int)HUF_flags_e.HUF_flags_suspectUncompressible) != 0 - && srcSize >= 4096 * 10 - ) + if ((flags & (int)HUF_flags_e.HUF_flags_suspectUncompressible) != 0 && srcSize >= 4096 * 10) { nuint largestTotal = 0; { diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/HufDecompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/HufDecompress.cs index 5da4f66d..26278708 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/HufDecompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/HufDecompress.cs @@ -369,8 +369,7 @@ public static unsafe partial class Methods if (MEM_32bits) while ( - BIT_reloadDStream(bitDPtr) == BIT_DStream_status.BIT_DStream_unfinished - && p < pEnd + BIT_reloadDStream(bitDPtr) == BIT_DStream_status.BIT_DStream_unfinished && p < pEnd ) *p++ = HUF_decodeSymbolX1(bitDPtr, dt, dtLog); while (p < pEnd) @@ -513,23 +512,19 @@ public static unsafe partial class Methods *op3++ = HUF_decodeSymbolX1(&bitD3, dt, dtLog); *op4++ = HUF_decodeSymbolX1(&bitD4, dt, dtLog); endSignal &= - BIT_reloadDStreamFast(&bitD1) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD1) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; endSignal &= - BIT_reloadDStreamFast(&bitD2) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD2) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; endSignal &= - BIT_reloadDStreamFast(&bitD3) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD3) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; endSignal &= - BIT_reloadDStreamFast(&bitD4) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD4) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; } @@ -552,9 +547,7 @@ public static unsafe partial class Methods & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4); if (endCheck == 0) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } return dstSize; @@ -569,13 +562,7 @@ public static unsafe partial class Methods uint* DTable ) { - return HUF_decompress4X1_usingDTable_internal_body( - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + return HUF_decompress4X1_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable); } private static void HUF_decompress4X1_usingDTable_internal_fast_c_loop( @@ -583,17 +570,17 @@ public static unsafe partial class Methods ) { ulong bits0, - bits1, - bits2, - bits3; + bits1, + bits2, + bits3; byte* ip0, - ip1, - ip2, - ip3; + ip1, + ip2, + ip3; byte* op0, - op1, - op2, - op3; + op1, + op2, + op3; ushort* dtable = (ushort*)args->dt; byte* oend = args->oend; byte* ilowest = args->ilowest; @@ -907,14 +894,7 @@ public static unsafe partial class Methods byte* oend = ZSTD_maybeNullPtrAdd((byte*)dst, (nint)dstSize); HUF_DecompressFastArgs args; { - nuint ret = HUF_DecompressFastArgs_init( - &args, - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + nuint ret = HUF_DecompressFastArgs_init(&args, dst, dstSize, cSrc, cSrcSize, DTable); { nuint err_code = ret; if (ERR_isError(err_code)) @@ -964,9 +944,7 @@ public static unsafe partial class Methods 11 ); if ((&args.op.e0)[i] != segmentEnd) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } } @@ -983,13 +961,7 @@ public static unsafe partial class Methods int flags ) { - return HUF_decompress1X1_usingDTable_internal_body( - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + return HUF_decompress1X1_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable); } private static nuint HUF_decompress4X1_usingDTable_internal( @@ -1217,16 +1189,16 @@ public static unsafe partial class Methods memcpy(DTable + 2, &DEltX2, sizeof(ulong)); break; default: - { - int i; - for (i = 0; i < skipSize; i += 8) { - memcpy(DTable + i + 0, &DEltX2, sizeof(ulong)); - memcpy(DTable + i + 2, &DEltX2, sizeof(ulong)); - memcpy(DTable + i + 4, &DEltX2, sizeof(ulong)); - memcpy(DTable + i + 6, &DEltX2, sizeof(ulong)); + int i; + for (i = 0; i < skipSize; i += 8) + { + memcpy(DTable + i + 0, &DEltX2, sizeof(ulong)); + memcpy(DTable + i + 2, &DEltX2, sizeof(ulong)); + memcpy(DTable + i + 4, &DEltX2, sizeof(ulong)); + memcpy(DTable + i + 6, &DEltX2, sizeof(ulong)); + } } - } break; } @@ -1326,8 +1298,8 @@ public static unsafe partial class Methods ) { uint tableLog, - maxW, - nbSymbols; + maxW, + nbSymbols; DTableDesc dtd = HUF_getDTableDesc(DTable); uint maxTableLog = dtd.maxTableLog; nuint iSize; @@ -1365,7 +1337,7 @@ public static unsafe partial class Methods { uint w, - nextRankStart = 0; + nextRankStart = 0; for (w = 1; w < maxW + 1; w++) { uint curr = nextRankStart; @@ -1667,13 +1639,11 @@ public static unsafe partial class Methods op2 += HUF_decodeSymbolX2(op2, &bitD2, dt, dtLog); op2 += HUF_decodeSymbolX2(op2, &bitD2, dt, dtLog); endSignal &= - BIT_reloadDStreamFast(&bitD1) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD1) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; endSignal &= - BIT_reloadDStreamFast(&bitD2) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD2) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; if (MEM_64bits) @@ -1689,13 +1659,11 @@ public static unsafe partial class Methods op4 += HUF_decodeSymbolX2(op4, &bitD4, dt, dtLog); op4 += HUF_decodeSymbolX2(op4, &bitD4, dt, dtLog); endSignal &= - BIT_reloadDStreamFast(&bitD3) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD3) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; endSignal &= - BIT_reloadDStreamFast(&bitD4) - == BIT_DStream_status.BIT_DStream_unfinished + BIT_reloadDStreamFast(&bitD4) == BIT_DStream_status.BIT_DStream_unfinished ? 1U : 0U; } @@ -1718,9 +1686,7 @@ public static unsafe partial class Methods & BIT_endOfDStream(&bitD3) & BIT_endOfDStream(&bitD4); if (endCheck == 0) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } return dstSize; @@ -1735,13 +1701,7 @@ public static unsafe partial class Methods uint* DTable ) { - return HUF_decompress4X2_usingDTable_internal_body( - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + return HUF_decompress4X2_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable); } private static void HUF_decompress4X2_usingDTable_internal_fast_c_loop( @@ -1749,21 +1709,21 @@ public static unsafe partial class Methods ) { ulong bits0, - bits1, - bits2, - bits3; + bits1, + bits2, + bits3; byte* ip0, - ip1, - ip2, - ip3; + ip1, + ip2, + ip3; byte* op0, - op1, - op2, - op3; + op1, + op2, + op3; byte* oend0, - oend1, - oend2, - oend3; + oend1, + oend2, + oend3; HUF_DEltX2* dtable = (HUF_DEltX2*)args->dt; byte* ilowest = args->ilowest; bits0 = args->bits[0]; @@ -2126,14 +2086,7 @@ public static unsafe partial class Methods byte* oend = ZSTD_maybeNullPtrAdd((byte*)dst, (nint)dstSize); HUF_DecompressFastArgs args; { - nuint ret = HUF_DecompressFastArgs_init( - &args, - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + nuint ret = HUF_DecompressFastArgs_init(&args, dst, dstSize, cSrc, cSrcSize, DTable); { nuint err_code = ret; if (ERR_isError(err_code)) @@ -2182,9 +2135,7 @@ public static unsafe partial class Methods 11 ); if ((&args.op.e0)[i] != segmentEnd) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } } @@ -2238,13 +2189,7 @@ public static unsafe partial class Methods int flags ) { - return HUF_decompress1X2_usingDTable_internal_body( - dst, - dstSize, - cSrc, - cSrcSize, - DTable - ); + return HUF_decompress1X2_usingDTable_internal_body(dst, dstSize, cSrc, cSrcSize, DTable); } private static nuint HUF_decompress1X2_DCtx_wksp( @@ -2462,14 +2407,7 @@ public static unsafe partial class Methods { DTableDesc dtd = HUF_getDTableDesc(DTable); return dtd.tableType != 0 - ? HUF_decompress1X2_usingDTable_internal( - dst, - maxDstSize, - cSrc, - cSrcSize, - DTable, - flags - ) + ? HUF_decompress1X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, flags) : HUF_decompress1X1_usingDTable_internal( dst, maxDstSize, @@ -2513,14 +2451,7 @@ public static unsafe partial class Methods { DTableDesc dtd = HUF_getDTableDesc(DTable); return dtd.tableType != 0 - ? HUF_decompress4X2_usingDTable_internal( - dst, - maxDstSize, - cSrc, - cSrcSize, - DTable, - flags - ) + ? HUF_decompress4X2_usingDTable_internal(dst, maxDstSize, cSrc, cSrcSize, DTable, flags) : HUF_decompress4X1_usingDTable_internal( dst, maxDstSize, diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Mem.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Mem.cs index aa18dfc2..673c7c95 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Mem.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Mem.cs @@ -138,7 +138,7 @@ public static unsafe partial class Methods if (!BitConverter.IsLittleEndian) { #if NET8_0_OR_GREATER - val = BinaryPrimitives.ReverseEndianness(val); + val = BinaryPrimitives.ReverseEndianness(val); #else val = ReverseEndiannessNative(val); #endif @@ -152,7 +152,7 @@ public static unsafe partial class Methods if (!BitConverter.IsLittleEndian) { #if NET8_0_OR_GREATER - val = BinaryPrimitives.ReverseEndianness(val); + val = BinaryPrimitives.ReverseEndianness(val); #else val = ReverseEndiannessNative(val); #endif diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/RSyncState_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/RSyncState_t.cs index 90f9dd50..7b5f08ad 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/RSyncState_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/RSyncState_t.cs @@ -5,4 +5,4 @@ public struct RSyncState_t public ulong hash; public ulong hitMask; public ulong primePower; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/RawSeqStore_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/RawSeqStore_t.cs index b9e5d8a3..07db05a1 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/RawSeqStore_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/RawSeqStore_t.cs @@ -18,13 +18,7 @@ public unsafe struct RawSeqStore_t /* The capacity starting from `seq` pointer */ public nuint capacity; - public RawSeqStore_t( - rawSeq* seq, - nuint pos, - nuint posInSequence, - nuint size, - nuint capacity - ) + public RawSeqStore_t(rawSeq* seq, nuint pos, nuint posInSequence, nuint size, nuint capacity) { this.seq = seq; this.pos = pos; diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/RoundBuff_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/RoundBuff_t.cs index ea0ed8a5..84e42ca4 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/RoundBuff_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/RoundBuff_t.cs @@ -25,4 +25,4 @@ public unsafe struct RoundBuff_t this.capacity = capacity; this.pos = pos; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/SeqDef_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/SeqDef_s.cs index 11c4aeba..1e5aac57 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/SeqDef_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/SeqDef_s.cs @@ -11,4 +11,4 @@ public struct SeqDef_s /* mlBase == matchLength - MINMATCH */ public ushort mlBase; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/XXH32_canonical_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/XXH32_canonical_t.cs index ecb03073..7da74bdf 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/XXH32_canonical_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/XXH32_canonical_t.cs @@ -7,4 +7,4 @@ public unsafe struct XXH32_canonical_t { /*!< Hash bytes, big endian */ public fixed byte digest[4]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Xxhash.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Xxhash.cs index 396a720d..ab8d814b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Xxhash.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Xxhash.cs @@ -164,12 +164,7 @@ public static unsafe partial class Methods * @param align Whether @p input is aligned. * @return The calculated hash. */ - private static uint XXH32_endian_align( - byte* input, - nuint len, - uint seed, - XXH_alignment align - ) + private static uint XXH32_endian_align(byte* input, nuint len, uint seed, XXH_alignment align) { uint h32; if (len >= 16) @@ -324,12 +319,7 @@ public static unsafe partial class Methods } h32 += state->total_len_32; - return XXH32_finalize( - h32, - (byte*)state->mem32, - state->memsize, - XXH_alignment.XXH_aligned - ); + return XXH32_finalize(h32, (byte*)state->mem32, state->memsize, XXH_alignment.XXH_aligned); } /*! @ingroup XXH32_family */ @@ -426,9 +416,7 @@ public static unsafe partial class Methods ulong k1 = XXH64_round(0, XXH_readLE64_align(ptr, align)); ptr += 8; hash ^= k1; - hash = - BitOperations.RotateLeft(hash, 27) * 0x9E3779B185EBCA87UL - + 0x85EBCA77C2B2AE63UL; + hash = BitOperations.RotateLeft(hash, 27) * 0x9E3779B185EBCA87UL + 0x85EBCA77C2B2AE63UL; len -= 8; } @@ -436,9 +424,7 @@ public static unsafe partial class Methods { hash ^= XXH_readLE32_align(ptr, align) * 0x9E3779B185EBCA87UL; ptr += 4; - hash = - BitOperations.RotateLeft(hash, 23) * 0xC2B2AE3D27D4EB4FUL - + 0x165667B19E3779F9UL; + hash = BitOperations.RotateLeft(hash, 23) * 0xC2B2AE3D27D4EB4FUL + 0x165667B19E3779F9UL; len -= 4; } @@ -460,12 +446,7 @@ public static unsafe partial class Methods * @param align Whether @p input is aligned. * @return The calculated hash. */ - private static ulong XXH64_endian_align( - byte* input, - nuint len, - ulong seed, - XXH_alignment align - ) + private static ulong XXH64_endian_align(byte* input, nuint len, ulong seed, XXH_alignment align) { ulong h64; if (len >= 32) diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZDICT_cover_params_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZDICT_cover_params_t.cs index 39811dfd..dfc4fecf 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZDICT_cover_params_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZDICT_cover_params_t.cs @@ -27,4 +27,4 @@ public struct ZDICT_cover_params_t /* Sets shrinkDictMaxRegression so that a smaller dictionary can be at worse shrinkDictMaxRegression% worse than the max dict size dictionary. */ public uint shrinkDictMaxRegression; public ZDICT_params_t zParams; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTDMT_bufferPool_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTDMT_bufferPool_s.cs index 1b9d33b4..0c64573a 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTDMT_bufferPool_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTDMT_bufferPool_s.cs @@ -8,4 +8,4 @@ public unsafe struct ZSTDMT_bufferPool_s public uint nbBuffers; public ZSTD_customMem cMem; public buffer_s* buffers; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_CDict_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_CDict_s.cs index 39d2bd17..02642d2a 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_CDict_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_CDict_s.cs @@ -27,4 +27,4 @@ public unsafe struct ZSTD_CDict_s * the same greedy/lazy matchfinder at compression time. */ public ZSTD_paramSwitch_e useRowMatchFinder; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDictHashSet.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDictHashSet.cs index 567c503c..c083994b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDictHashSet.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDictHashSet.cs @@ -6,4 +6,4 @@ public unsafe struct ZSTD_DDictHashSet public ZSTD_DDict_s** ddictPtrTable; public nuint ddictPtrTableSize; public nuint ddictPtrCount; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDict_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDict_s.cs index 50477dc4..33e86e9f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDict_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DDict_s.cs @@ -12,4 +12,4 @@ public unsafe struct ZSTD_DDict_s public uint dictID; public uint entropyPresent; public ZSTD_customMem cMem; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DefaultPolicy_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DefaultPolicy_e.cs index ed5224e8..ac4ad573 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DefaultPolicy_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_DefaultPolicy_e.cs @@ -4,4 +4,4 @@ public enum ZSTD_DefaultPolicy_e { ZSTD_defaultDisallowed = 0, ZSTD_defaultAllowed = 1, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_ErrorCode.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_ErrorCode.cs index 506f10fe..9e5de435 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_ErrorCode.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_ErrorCode.cs @@ -56,4 +56,4 @@ public enum ZSTD_ErrorCode /* never EVER use this value directly, it can change in future versions! Use ZSTD_isError() instead */ ZSTD_error_maxCode = 120, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_OptPrice_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_OptPrice_e.cs index bde76eae..229a5da8 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_OptPrice_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_OptPrice_e.cs @@ -4,4 +4,4 @@ public enum ZSTD_OptPrice_e { zop_dynamic = 0, zop_predef, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_SequencePosition.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_SequencePosition.cs index 3b2d2d6f..db0ec511 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_SequencePosition.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_SequencePosition.cs @@ -10,4 +10,4 @@ public struct ZSTD_SequencePosition /* Number of bytes given by sequences provided so far */ public nuint posInSrc; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_buffered_policy_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_buffered_policy_e.cs index 3ecc07f5..8d5a1a91 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_buffered_policy_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_buffered_policy_e.cs @@ -9,4 +9,4 @@ public enum ZSTD_buffered_policy_e { ZSTDb_not_buffered, ZSTDb_buffered, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cStreamStage.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cStreamStage.cs index 3c1343c4..c929b7fa 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cStreamStage.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cStreamStage.cs @@ -5,4 +5,4 @@ public enum ZSTD_cStreamStage zcss_init = 0, zcss_load, zcss_flush, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compResetPolicy_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compResetPolicy_e.cs index 36fb340d..d943004d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compResetPolicy_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compResetPolicy_e.cs @@ -11,4 +11,4 @@ public enum ZSTD_compResetPolicy_e { ZSTDcrp_makeClean, ZSTDcrp_leaveDirty, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compressionStage_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compressionStage_e.cs index 4f31af03..9ffa4833 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compressionStage_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_compressionStage_e.cs @@ -9,4 +9,4 @@ public enum ZSTD_compressionStage_e ZSTDcs_init, ZSTDcs_ongoing, ZSTDcs_ending, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_customMem.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_customMem.cs index 21654b29..16776a74 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_customMem.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_customMem.cs @@ -12,4 +12,4 @@ public unsafe struct ZSTD_customMem this.customFree = customFree; this.opaque = opaque; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cwksp_static_alloc_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cwksp_static_alloc_e.cs index 82f30a25..8f290f3a 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cwksp_static_alloc_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_cwksp_static_alloc_e.cs @@ -9,4 +9,4 @@ public enum ZSTD_cwksp_static_alloc_e { ZSTD_cwksp_dynamic_alloc, ZSTD_cwksp_static_alloc, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dStreamStage.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dStreamStage.cs index 7cc247e1..851e06f7 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dStreamStage.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dStreamStage.cs @@ -7,4 +7,4 @@ public enum ZSTD_dStreamStage zdss_read, zdss_load, zdss_flush, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictContentType_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictContentType_e.cs index 2b821ecf..3b97b12d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictContentType_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictContentType_e.cs @@ -10,4 +10,4 @@ public enum ZSTD_dictContentType_e /* refuses to load a dictionary if it does not respect Zstandard's specification, starting with ZSTD_MAGIC_DICTIONARY */ ZSTD_dct_fullDict = 2, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictUses_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictUses_e.cs index e7f2d2ef..314507c5 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictUses_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_dictUses_e.cs @@ -10,4 +10,4 @@ public enum ZSTD_dictUses_e /* Use the dictionary once and set to ZSTD_dont_use */ ZSTD_use_once = 1, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_entropyDTables_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_entropyDTables_t.cs index 84a487a7..91dd9d7d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_entropyDTables_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_entropyDTables_t.cs @@ -19,11 +19,11 @@ public unsafe struct ZSTD_entropyDTables_t public fixed uint workspace[157]; #if NET8_0_OR_GREATER - [InlineArray(513)] - public unsafe struct _LLTable_e__FixedBuffer - { - public ZSTD_seqSymbol e0; - } + [InlineArray(513)] + public unsafe struct _LLTable_e__FixedBuffer + { + public ZSTD_seqSymbol e0; + } #else public unsafe struct _LLTable_e__FixedBuffer @@ -545,11 +545,11 @@ public unsafe struct ZSTD_entropyDTables_t #endif #if NET8_0_OR_GREATER - [InlineArray(257)] - public unsafe struct _OFTable_e__FixedBuffer - { - public ZSTD_seqSymbol e0; - } + [InlineArray(257)] + public unsafe struct _OFTable_e__FixedBuffer + { + public ZSTD_seqSymbol e0; + } #else public unsafe struct _OFTable_e__FixedBuffer @@ -815,11 +815,11 @@ public unsafe struct ZSTD_entropyDTables_t #endif #if NET8_0_OR_GREATER - [InlineArray(513)] - public unsafe struct _MLTable_e__FixedBuffer - { - public ZSTD_seqSymbol e0; - } + [InlineArray(513)] + public unsafe struct _MLTable_e__FixedBuffer + { + public ZSTD_seqSymbol e0; + } #else public unsafe struct _MLTable_e__FixedBuffer @@ -1339,4 +1339,4 @@ public unsafe struct ZSTD_entropyDTables_t public ZSTD_seqSymbol e512; } #endif -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_forceIgnoreChecksum_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_forceIgnoreChecksum_e.cs index f4288622..a8322621 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_forceIgnoreChecksum_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_forceIgnoreChecksum_e.cs @@ -5,4 +5,4 @@ public enum ZSTD_forceIgnoreChecksum_e /* Note: this enum controls ZSTD_d_forceIgnoreChecksum */ ZSTD_d_validateChecksum = 0, ZSTD_d_ignoreChecksum = 1, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameHeader.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameHeader.cs index afa709f0..8c80f759 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameHeader.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameHeader.cs @@ -18,4 +18,4 @@ public struct ZSTD_frameHeader public uint checksumFlag; public uint _reserved1; public uint _reserved2; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameProgression.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameProgression.cs index 68a380fc..adf34b4d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameProgression.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameProgression.cs @@ -19,4 +19,4 @@ public struct ZSTD_frameProgression /* MT only : nb of workers actively compressing at probe time */ public uint nbActiveWorkers; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameType_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameType_e.cs index 80e6e839..a399748f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameType_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_frameType_e.cs @@ -4,4 +4,4 @@ public enum ZSTD_frameType_e { ZSTD_frame, ZSTD_skippableFrame, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_fseCTables_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_fseCTables_t.cs index 0fca629f..3a9d621b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_fseCTables_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_fseCTables_t.cs @@ -8,4 +8,4 @@ public unsafe struct ZSTD_fseCTables_t public FSE_repeat offcode_repeatMode; public FSE_repeat matchlength_repeatMode; public FSE_repeat litlength_repeatMode; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_hufCTables_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_hufCTables_t.cs index 7ba93122..bedd8c8b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_hufCTables_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_hufCTables_t.cs @@ -8,11 +8,11 @@ public unsafe struct ZSTD_hufCTables_t public HUF_repeat repeatMode; #if NET8_0_OR_GREATER - [InlineArray(257)] - public unsafe struct _CTable_e__FixedBuffer - { - public nuint e0; - } + [InlineArray(257)] + public unsafe struct _CTable_e__FixedBuffer + { + public nuint e0; + } #else public unsafe struct _CTable_e__FixedBuffer diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_inBuffer_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_inBuffer_s.cs index 14c4f2c5..58242a2c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_inBuffer_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_inBuffer_s.cs @@ -13,4 +13,4 @@ public unsafe struct ZSTD_inBuffer_s /**< position where reading stopped. Will be updated. Necessarily 0 <= pos <= size */ public nuint pos; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_indexResetPolicy_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_indexResetPolicy_e.cs index f461d52d..b3638aa0 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_indexResetPolicy_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_indexResetPolicy_e.cs @@ -9,4 +9,4 @@ public enum ZSTD_indexResetPolicy_e { ZSTDirp_continue, ZSTDirp_reset, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_localDict.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_localDict.cs index 3ffa6739..4b970451 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_localDict.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_localDict.cs @@ -7,4 +7,4 @@ public unsafe struct ZSTD_localDict public nuint dictSize; public ZSTD_dictContentType_e dictContentType; public ZSTD_CDict_s* cdict; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_longLengthType_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_longLengthType_e.cs index 1994b34d..141643f2 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_longLengthType_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_longLengthType_e.cs @@ -11,4 +11,4 @@ public enum ZSTD_longLengthType_e /* represents a long match */ ZSTD_llt_matchLength = 2, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_match_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_match_t.cs index bc953181..fa44b9ec 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_match_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_match_t.cs @@ -10,4 +10,4 @@ public struct ZSTD_match_t /* Raw length of match */ public uint len; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_outBuffer_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_outBuffer_s.cs index 38dc2171..c2cc0089 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_outBuffer_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_outBuffer_s.cs @@ -10,4 +10,4 @@ public unsafe struct ZSTD_outBuffer_s /**< position where writing stopped. Will be updated. Necessarily 0 <= pos <= size */ public nuint pos; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_parameters.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_parameters.cs index eefcdcb4..ebdf1969 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_parameters.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_parameters.cs @@ -4,4 +4,4 @@ public struct ZSTD_parameters { public ZSTD_compressionParameters cParams; public ZSTD_frameParameters fParams; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_resetTarget_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_resetTarget_e.cs index 0da6810a..679e8b28 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_resetTarget_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_resetTarget_e.cs @@ -4,4 +4,4 @@ public enum ZSTD_resetTarget_e { ZSTD_resetTarget_CDict, ZSTD_resetTarget_CCtx, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_seqSymbol.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_seqSymbol.cs index d088f245..622ff4fc 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_seqSymbol.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_seqSymbol.cs @@ -14,4 +14,4 @@ public struct ZSTD_seqSymbol this.nbBits = nbBits; this.baseValue = baseValue; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_sequenceFormat_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_sequenceFormat_e.cs index 606e7be2..3b6ca525 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_sequenceFormat_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_sequenceFormat_e.cs @@ -7,4 +7,4 @@ public enum ZSTD_sequenceFormat_e /* ZSTD_Sequence[] contains explicit block delimiters */ ZSTD_sf_explicitBlockDelimiters = 1, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_tableFillPurpose_e.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_tableFillPurpose_e.cs index 3f58f6ad..f218de33 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_tableFillPurpose_e.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZSTD_tableFillPurpose_e.cs @@ -4,4 +4,4 @@ public enum ZSTD_tableFillPurpose_e { ZSTD_tfp_forCCtx, ZSTD_tfp_forCDict, -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/Zdict.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/Zdict.cs index 77c11d81..a79aa008 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/Zdict.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/Zdict.cs @@ -172,13 +172,13 @@ public static unsafe partial class Methods }; ZSTD_parameters @params; uint u, - huffLog = 11, - Offlog = 8, - mlLog = 9, - llLog = 9, - total; + huffLog = 11, + Offlog = 8, + mlLog = 9, + llLog = 9, + total; nuint pos = 0, - errorCode; + errorCode; nuint eSize = 0; nuint totalSrcSize = ZDICT_totalSampleSize(fileSizes, nbFiles); nuint averageSampleSize = totalSrcSize / (nbFiles + (uint)(nbFiles == 0 ? 1 : 0)); @@ -186,9 +186,7 @@ public static unsafe partial class Methods uint* wksp = stackalloc uint[1216]; if (offcodeMax > 30) { - eSize = unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionaryCreation_failed) - ); + eSize = unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionaryCreation_failed)); goto _cleanup; } @@ -285,14 +283,7 @@ public static unsafe partial class Methods total = 0; for (u = 0; u <= offcodeMax; u++) total += offcodeCount[u]; - errorCode = FSE_normalizeCount( - offcodeNCount, - Offlog, - offcodeCount, - total, - offcodeMax, - 1 - ); + errorCode = FSE_normalizeCount(offcodeNCount, Offlog, offcodeCount, total, offcodeMax, 1); if (ERR_isError(errorCode)) { eSize = errorCode; @@ -303,14 +294,7 @@ public static unsafe partial class Methods total = 0; for (u = 0; u <= 52; u++) total += matchLengthCount[u]; - errorCode = FSE_normalizeCount( - matchLengthNCount, - mlLog, - matchLengthCount, - total, - 52, - 1 - ); + errorCode = FSE_normalizeCount(matchLengthNCount, mlLog, matchLengthCount, total, 52, 1); if (ERR_isError(errorCode)) { eSize = errorCode; @@ -653,4 +637,4 @@ public static unsafe partial class Methods @params ); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompress.cs index a10b181e..8198034b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompress.cs @@ -26,8 +26,8 @@ public static unsafe partial class Methods srcSize >= (sizeof(nuint) == 8 ? 0xFF00FF00FF00FF00UL : 0xFF00FF00U) ? 0 : srcSize - + (srcSize >> 8) - + (srcSize < 128 << 10 ? (128 << 10) - srcSize >> 11 : 0); + + (srcSize >> 8) + + (srcSize < 128 << 10 ? (128 << 10) - srcSize >> 11 : 0); if (r == 0) return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_srcSize_wrong)); return r; @@ -50,10 +50,7 @@ public static unsafe partial class Methods public static ZSTD_CCtx_s* ZSTD_createCCtx_advanced(ZSTD_customMem customMem) { - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; { ZSTD_CCtx_s* cctx = (ZSTD_CCtx_s*)ZSTD_customMalloc( @@ -205,9 +202,9 @@ public static unsafe partial class Methods if (cctx == null) return 0; return (nuint)(cctx->workspace.workspace == cctx ? 0 : sizeof(ZSTD_CCtx_s)) - + ZSTD_cwksp_sizeof(&cctx->workspace) - + ZSTD_sizeof_localDict(cctx->localDict) - + ZSTD_sizeof_mtctx(cctx); + + ZSTD_cwksp_sizeof(&cctx->workspace) + + ZSTD_sizeof_localDict(cctx->localDict) + + ZSTD_sizeof_mtctx(cctx); } public static nuint ZSTD_sizeof_CStream(ZSTD_CCtx_s* zcs) @@ -236,10 +233,9 @@ public static unsafe partial class Methods { assert(mode != ZSTD_paramSwitch_e.ZSTD_ps_auto); return - ZSTD_rowMatchFinderSupported(strategy) != 0 - && mode == ZSTD_paramSwitch_e.ZSTD_ps_enable - ? 1 - : 0; + ZSTD_rowMatchFinderSupported(strategy) != 0 && mode == ZSTD_paramSwitch_e.ZSTD_ps_enable + ? 1 + : 0; } /* Returns row matchfinder usage given an initial mode and cParams */ @@ -282,9 +278,9 @@ public static unsafe partial class Methods return forDDSDict != 0 || strategy != ZSTD_strategy.ZSTD_fast - && ZSTD_rowMatchFinderUsed(strategy, useRowMatchFinder) == 0 - ? 1 - : 0; + && ZSTD_rowMatchFinderUsed(strategy, useRowMatchFinder) == 0 + ? 1 + : 0; } /* Returns ZSTD_ps_enable if compression parameters are such that we should @@ -345,8 +341,8 @@ public static unsafe partial class Methods return cParams->strategy == ZSTD_strategy.ZSTD_fast || cParams->strategy == ZSTD_strategy.ZSTD_dfast - ? 1 - : 0; + ? 1 + : 0; } private static ZSTD_CCtx_params_s ZSTD_makeCCtxParamsFromCParams( @@ -390,10 +386,7 @@ public static unsafe partial class Methods private static ZSTD_CCtx_params_s* ZSTD_createCCtxParams_advanced(ZSTD_customMem customMem) { ZSTD_CCtx_params_s* @params; - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; @params = (ZSTD_CCtx_params_s*)ZSTD_customCalloc( (nuint)sizeof(ZSTD_CCtx_params_s), @@ -454,10 +447,7 @@ public static unsafe partial class Methods * Initializes the compression parameters of cctxParams according to * compression level. All other parameters are reset to their default values. */ - public static nuint ZSTD_CCtxParams_init( - ZSTD_CCtx_params_s* cctxParams, - int compressionLevel - ) + public static nuint ZSTD_CCtxParams_init(ZSTD_CCtx_params_s* cctxParams, int compressionLevel) { if (cctxParams == null) { @@ -812,11 +802,7 @@ public static unsafe partial class Methods * new parameters will be active for next job only (after a flush()). * @return : an error code (which can be tested using ZSTD_isError()). */ - public static nuint ZSTD_CCtx_setParameter( - ZSTD_CCtx_s* cctx, - ZSTD_cParameter param, - int value - ) + public static nuint ZSTD_CCtx_setParameter(ZSTD_CCtx_s* cctx, ZSTD_cParameter param, int value) { if (cctx->streamStage != ZSTD_cStreamStage.zcss_init) { @@ -881,9 +867,7 @@ public static unsafe partial class Methods case ZSTD_cParameter.ZSTD_c_experimentalParam19: break; default: - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); } return ZSTD_CCtxParams_setParameter(&cctx->requestedParams, param, value); @@ -906,14 +890,9 @@ public static unsafe partial class Methods switch (param) { case ZSTD_cParameter.ZSTD_c_experimentalParam2: - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam2, value) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam2, value) == 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->format = (ZSTD_format_e)value; @@ -995,9 +974,7 @@ public static unsafe partial class Methods case ZSTD_cParameter.ZSTD_c_targetLength: if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_targetLength, value) == 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->cParams.targetLength = (uint)value; @@ -1029,15 +1006,11 @@ public static unsafe partial class Methods { ZSTD_dictAttachPref_e pref = (ZSTD_dictAttachPref_e)value; if ( - ZSTD_cParam_withinBounds( - ZSTD_cParameter.ZSTD_c_experimentalParam4, - (int)pref - ) == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam4, (int)pref) + == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->attachDictPref = pref; @@ -1048,15 +1021,11 @@ public static unsafe partial class Methods { ZSTD_paramSwitch_e lcm = (ZSTD_paramSwitch_e)value; if ( - ZSTD_cParam_withinBounds( - ZSTD_cParameter.ZSTD_c_experimentalParam5, - (int)lcm - ) == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam5, (int)lcm) + == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->literalCompressionMode = lcm; @@ -1064,13 +1033,13 @@ public static unsafe partial class Methods } case ZSTD_cParameter.ZSTD_c_nbWorkers: - { - nuint err_code = ZSTD_cParam_clampBounds(param, &value); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_cParam_clampBounds(param, &value); + if (ERR_isError(err_code)) + { + return err_code; + } } - } CCtxParams->nbWorkers = value; return (nuint)CCtxParams->nbWorkers; @@ -1078,42 +1047,42 @@ public static unsafe partial class Methods if (value != 0 && value < 512 * (1 << 10)) value = 512 * (1 << 10); - { - nuint err_code = ZSTD_cParam_clampBounds(param, &value); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_cParam_clampBounds(param, &value); + if (ERR_isError(err_code)) + { + return err_code; + } } - } assert(value >= 0); CCtxParams->jobSize = (nuint)value; return CCtxParams->jobSize; case ZSTD_cParameter.ZSTD_c_overlapLog: - { - nuint err_code = ZSTD_cParam_clampBounds( - ZSTD_cParameter.ZSTD_c_overlapLog, - &value - ); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_cParam_clampBounds( + ZSTD_cParameter.ZSTD_c_overlapLog, + &value + ); + if (ERR_isError(err_code)) + { + return err_code; + } } - } CCtxParams->overlapLog = value; return (nuint)CCtxParams->overlapLog; case ZSTD_cParameter.ZSTD_c_experimentalParam1: - { - nuint err_code = ZSTD_cParam_clampBounds( - ZSTD_cParameter.ZSTD_c_overlapLog, - &value - ); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_cParam_clampBounds( + ZSTD_cParameter.ZSTD_c_overlapLog, + &value + ); + if (ERR_isError(err_code)) + { + return err_code; + } } - } CCtxParams->rsyncable = value; return (nuint)CCtxParams->rsyncable; @@ -1128,9 +1097,7 @@ public static unsafe partial class Methods ) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->ldmParams.enableLdm = (ZSTD_paramSwitch_e)value; @@ -1148,9 +1115,7 @@ public static unsafe partial class Methods return CCtxParams->ldmParams.hashLog; case ZSTD_cParameter.ZSTD_c_ldmMinMatch: if (value != 0) - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_ldmMinMatch, value) == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_ldmMinMatch, value) == 0) { return unchecked( (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) @@ -1175,10 +1140,7 @@ public static unsafe partial class Methods return CCtxParams->ldmParams.bucketSizeLog; case ZSTD_cParameter.ZSTD_c_ldmHashRateLog: if (value != 0) - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_ldmHashRateLog, value) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_ldmHashRateLog, value) == 0) { return unchecked( (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) @@ -1207,10 +1169,8 @@ public static unsafe partial class Methods case ZSTD_cParameter.ZSTD_c_experimentalParam7: if (value != 0) if ( - ZSTD_cParam_withinBounds( - ZSTD_cParameter.ZSTD_c_experimentalParam7, - value - ) == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam7, value) + == 0 ) { return unchecked( @@ -1221,131 +1181,99 @@ public static unsafe partial class Methods CCtxParams->srcSizeHint = value; return (nuint)CCtxParams->srcSizeHint; case ZSTD_cParameter.ZSTD_c_experimentalParam9: - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam9, value) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam9, value) == 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->inBufferMode = (ZSTD_bufferMode_e)value; return (nuint)CCtxParams->inBufferMode; case ZSTD_cParameter.ZSTD_c_experimentalParam10: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam10, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam10, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->outBufferMode = (ZSTD_bufferMode_e)value; return (nuint)CCtxParams->outBufferMode; case ZSTD_cParameter.ZSTD_c_experimentalParam11: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam11, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam11, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->blockDelimiters = (ZSTD_sequenceFormat_e)value; return (nuint)CCtxParams->blockDelimiters; case ZSTD_cParameter.ZSTD_c_experimentalParam12: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam12, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam12, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->validateSequences = value; return (nuint)CCtxParams->validateSequences; case ZSTD_cParameter.ZSTD_c_experimentalParam13: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam13, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam13, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->postBlockSplitter = (ZSTD_paramSwitch_e)value; return (nuint)CCtxParams->postBlockSplitter; case ZSTD_cParameter.ZSTD_c_experimentalParam20: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam20, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam20, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->preBlockSplitter_level = value; return (nuint)CCtxParams->preBlockSplitter_level; case ZSTD_cParameter.ZSTD_c_experimentalParam14: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam14, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam14, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->useRowMatchFinder = (ZSTD_paramSwitch_e)value; return (nuint)CCtxParams->useRowMatchFinder; case ZSTD_cParameter.ZSTD_c_experimentalParam15: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam15, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam15, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->deterministicRefPrefix = !(value == 0) ? 1 : 0; return (nuint)CCtxParams->deterministicRefPrefix; case ZSTD_cParameter.ZSTD_c_experimentalParam16: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam16, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam16, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->prefetchCDictTables = (ZSTD_paramSwitch_e)value; return (nuint)CCtxParams->prefetchCDictTables; case ZSTD_cParameter.ZSTD_c_experimentalParam17: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam17, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam17, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->enableMatchFinderFallback = value; @@ -1353,10 +1281,8 @@ public static unsafe partial class Methods case ZSTD_cParameter.ZSTD_c_experimentalParam18: if (value != 0) if ( - ZSTD_cParam_withinBounds( - ZSTD_cParameter.ZSTD_c_experimentalParam18, - value - ) == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam18, value) + == 0 ) { return unchecked( @@ -1369,21 +1295,16 @@ public static unsafe partial class Methods return CCtxParams->maxBlockSize; case ZSTD_cParameter.ZSTD_c_experimentalParam19: if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam19, value) - == 0 + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_experimentalParam19, value) == 0 ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } CCtxParams->searchForExternalRepcodes = (ZSTD_paramSwitch_e)value; return (nuint)CCtxParams->searchForExternalRepcodes; default: - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); } } @@ -1392,11 +1313,7 @@ public static unsafe partial class Methods * and store it into int* value. * @return : 0, or an error code (which can be tested with ZSTD_isError()). */ - public static nuint ZSTD_CCtx_getParameter( - ZSTD_CCtx_s* cctx, - ZSTD_cParameter param, - int* value - ) + public static nuint ZSTD_CCtx_getParameter(ZSTD_CCtx_s* cctx, ZSTD_cParameter param, int* value) { return ZSTD_CCtxParams_getParameter(&cctx->requestedParams, param, value); } @@ -1533,9 +1450,7 @@ public static unsafe partial class Methods *value = (int)CCtxParams->searchForExternalRepcodes; break; default: - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); } return 0; @@ -1574,10 +1489,7 @@ public static unsafe partial class Methods * @return 0 on success, or an error code (can be checked with ZSTD_isError()). * On failure, no parameters are updated. */ - public static nuint ZSTD_CCtx_setCParams( - ZSTD_CCtx_s* cctx, - ZSTD_compressionParameters cparams - ) + public static nuint ZSTD_CCtx_setCParams(ZSTD_CCtx_s* cctx, ZSTD_compressionParameters cparams) { { /* only update if all parameters are valid */ @@ -2049,18 +1961,12 @@ public static unsafe partial class Methods @return : 0, or an error code if one value is beyond authorized range */ public static nuint ZSTD_checkCParams(ZSTD_compressionParameters cParams) { - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_windowLog, (int)cParams.windowLog) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_windowLog, (int)cParams.windowLog) == 0) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_chainLog, (int)cParams.chainLog) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_chainLog, (int)cParams.chainLog) == 0) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } @@ -2070,36 +1976,25 @@ public static unsafe partial class Methods return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_searchLog, (int)cParams.searchLog) == 0) + { + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); + } + + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_minMatch, (int)cParams.minMatch) == 0) + { + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); + } + if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_searchLog, (int)cParams.searchLog) + ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_targetLength, (int)cParams.targetLength) == 0 ) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_minMatch, (int)cParams.minMatch) - == 0 - ) - { - return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); - } - - if ( - ZSTD_cParam_withinBounds( - ZSTD_cParameter.ZSTD_c_targetLength, - (int)cParams.targetLength - ) == 0 - ) - { - return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); - } - - if ( - ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_strategy, (int)cParams.strategy) - == 0 - ) + if (ZSTD_cParam_withinBounds(ZSTD_cParameter.ZSTD_c_strategy, (int)cParams.strategy) == 0) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound)); } @@ -2110,9 +2005,7 @@ public static unsafe partial class Methods /** ZSTD_clampCParams() : * make CParam values within valid range. * @return : valid CParams */ - private static ZSTD_compressionParameters ZSTD_clampCParams( - ZSTD_compressionParameters cParams - ) + private static ZSTD_compressionParameters ZSTD_clampCParams(ZSTD_compressionParameters cParams) { { ZSTD_bounds bounds = ZSTD_cParam_getBounds(ZSTD_cParameter.ZSTD_c_windowLog); @@ -2421,25 +2314,20 @@ public static unsafe partial class Methods nuint h3Size = hashLog3 != 0 ? (nuint)1 << (int)hashLog3 : 0; /* We don't use ZSTD_cwksp_alloc_size() here because the tables aren't * surrounded by redzones in ASAN. */ - nuint tableSpace = - chainSize * sizeof(uint) + hSize * sizeof(uint) + h3Size * sizeof(uint); + nuint tableSpace = chainSize * sizeof(uint) + hSize * sizeof(uint) + h3Size * sizeof(uint); nuint optPotentialSpace = ZSTD_cwksp_aligned64_alloc_size((52 + 1) * sizeof(uint)) + ZSTD_cwksp_aligned64_alloc_size((35 + 1) * sizeof(uint)) + ZSTD_cwksp_aligned64_alloc_size((31 + 1) * sizeof(uint)) + ZSTD_cwksp_aligned64_alloc_size((1 << 8) * sizeof(uint)) + ZSTD_cwksp_aligned64_alloc_size((nuint)(((1 << 12) + 3) * sizeof(ZSTD_match_t))) - + ZSTD_cwksp_aligned64_alloc_size( - (nuint)(((1 << 12) + 3) * sizeof(ZSTD_optimal_t)) - ); + + ZSTD_cwksp_aligned64_alloc_size((nuint)(((1 << 12) + 3) * sizeof(ZSTD_optimal_t))); nuint lazyAdditionalSpace = ZSTD_rowMatchFinderUsed(cParams->strategy, useRowMatchFinder) != 0 ? ZSTD_cwksp_aligned64_alloc_size(hSize) : 0; nuint optSpace = - forCCtx != 0 && cParams->strategy >= ZSTD_strategy.ZSTD_btopt - ? optPotentialSpace - : 0; + forCCtx != 0 && cParams->strategy >= ZSTD_strategy.ZSTD_btopt ? optPotentialSpace : 0; nuint slackSpace = ZSTD_cwksp_slack_space_required(); assert(useRowMatchFinder != ZSTD_paramSwitch_e.ZSTD_ps_auto); return tableSpace + optSpace + slackSpace + lazyAdditionalSpace; @@ -2494,15 +2382,12 @@ public static unsafe partial class Methods ldmParams->enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable ? ZSTD_cwksp_aligned64_alloc_size(maxNbLdmSeq * (nuint)sizeof(rawSeq)) : 0; - nuint bufferSpace = - ZSTD_cwksp_alloc_size(buffInSize) + ZSTD_cwksp_alloc_size(buffOutSize); + nuint bufferSpace = ZSTD_cwksp_alloc_size(buffInSize) + ZSTD_cwksp_alloc_size(buffOutSize); nuint cctxSpace = isStatic != 0 ? ZSTD_cwksp_alloc_size((nuint)sizeof(ZSTD_CCtx_s)) : 0; nuint maxNbExternalSeq = ZSTD_sequenceBound(blockSize); nuint externalSeqSpace = useSequenceProducer != 0 - ? ZSTD_cwksp_aligned64_alloc_size( - maxNbExternalSeq * (nuint)sizeof(ZSTD_Sequence) - ) + ? ZSTD_cwksp_aligned64_alloc_size(maxNbExternalSeq * (nuint)sizeof(ZSTD_Sequence)) : 0; nuint neededSpace = cctxSpace @@ -2568,13 +2453,13 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_srcSizeTiers => - new ulong[4] { 16 * (1 << 10), 128 * (1 << 10), 256 * (1 << 10), unchecked(0UL - 1) }; - private static ulong* srcSizeTiers => - (ulong*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_srcSizeTiers) - ); + private static ReadOnlySpan Span_srcSizeTiers => + new ulong[4] { 16 * (1 << 10), 128 * (1 << 10), 256 * (1 << 10), unchecked(0UL - 1) }; + private static ulong* srcSizeTiers => + (ulong*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_srcSizeTiers) + ); #else private static readonly ulong* srcSizeTiers = GetArrayPointer( @@ -2671,8 +2556,7 @@ public static unsafe partial class Methods ZSTD_CParamMode_e.ZSTD_cpm_noAttachDict ); nuint blockSize = - ZSTD_resolveMaxBlockSize(@params->maxBlockSize) - < (nuint)1 << (int)cParams.windowLog + ZSTD_resolveMaxBlockSize(@params->maxBlockSize) < (nuint)1 << (int)cParams.windowLog ? ZSTD_resolveMaxBlockSize(@params->maxBlockSize) : (nuint)1 << (int)cParams.windowLog; nuint inBuffSize = @@ -2701,9 +2585,7 @@ public static unsafe partial class Methods } } - public static nuint ZSTD_estimateCStreamSize_usingCParams( - ZSTD_compressionParameters cParams - ) + public static nuint ZSTD_estimateCStreamSize_usingCParams(ZSTD_compressionParameters cParams) { ZSTD_CCtx_params_s initialParams = ZSTD_makeCCtxParamsFromCParams(cParams); if (ZSTD_rowMatchFinderSupported(cParams.strategy) != 0) @@ -2884,8 +2766,7 @@ public static unsafe partial class Methods ZSTD_allocateChainTable( cParams->strategy, useRowMatchFinder, - ms->dedicatedDictSearch != 0 - && forWho == ZSTD_resetTarget_e.ZSTD_resetTarget_CDict + ms->dedicatedDictSearch != 0 && forWho == ZSTD_resetTarget_e.ZSTD_resetTarget_CDict ? 1U : 0U ) != 0 @@ -2964,10 +2845,7 @@ public static unsafe partial class Methods ws, (52 + 1) * sizeof(uint) ); - ms->opt.offCodeFreq = (uint*)ZSTD_cwksp_reserve_aligned64( - ws, - (31 + 1) * sizeof(uint) - ); + ms->opt.offCodeFreq = (uint*)ZSTD_cwksp_reserve_aligned64(ws, (31 + 1) * sizeof(uint)); ms->opt.matchTable = (ZSTD_match_t*)ZSTD_cwksp_reserve_aligned64( ws, (nuint)(((1 << 12) + 3) * sizeof(ZSTD_match_t)) @@ -2992,8 +2870,8 @@ public static unsafe partial class Methods return (nuint)(w.nextSrc - w.@base) > (MEM_64bits ? 3500U * (1 << 20) : 2000U * (1 << 20)) - 16 * (1 << 20) - ? 1 - : 0; + ? 1 + : 0; } /** ZSTD_dictTooBig(): @@ -3006,8 +2884,8 @@ public static unsafe partial class Methods return loadedDictSize > unchecked((uint)-1) - (MEM_64bits ? 3500U * (1 << 20) : 2000U * (1 << 20)) - ? 1 - : 0; + ? 1 + : 0; } /*! ZSTD_resetCCtx_internal() : @@ -3307,10 +3185,10 @@ public static unsafe partial class Methods || pledgedSrcSize == unchecked(0UL - 1) || @params->attachDictPref == ZSTD_dictAttachPref_e.ZSTD_dictForceAttach ) - && @params->attachDictPref != ZSTD_dictAttachPref_e.ZSTD_dictForceCopy - && @params->forceWindow == 0 - ? 1 - : 0; + && @params->attachDictPref != ZSTD_dictAttachPref_e.ZSTD_dictForceCopy + && @params->forceWindow == 0 + ? 1 + : 0; } private static nuint ZSTD_resetCCtx_byAttachingCDict( @@ -3373,9 +3251,9 @@ public static unsafe partial class Methods } cctx->blockState.matchState.loadedDictEnd = cctx->blockState - .matchState - .window - .dictLimit; + .matchState + .window + .dictLimit; } } @@ -3455,8 +3333,7 @@ public static unsafe partial class Methods { /* DDS guaranteed disabled */ nuint chainSize = - ZSTD_allocateChainTable(cdict_cParams->strategy, cdict->useRowMatchFinder, 0) - != 0 + ZSTD_allocateChainTable(cdict_cParams->strategy, cdict->useRowMatchFinder, 0) != 0 ? (nuint)1 << (int)cdict_cParams->chainLog : 0; nuint hSize = (nuint)1 << (int)cdict_cParams->hashLog; @@ -3534,13 +3411,7 @@ public static unsafe partial class Methods { if (ZSTD_shouldAttachDict(cdict, @params, pledgedSrcSize) != 0) { - return ZSTD_resetCCtx_byAttachingCDict( - cctx, - cdict, - *@params, - pledgedSrcSize, - zbuff - ); + return ZSTD_resetCCtx_byAttachingCDict(cctx, cdict, *@params, pledgedSrcSize, zbuff); } else { @@ -3574,9 +3445,7 @@ public static unsafe partial class Methods @params.cParams = srcCCtx->appliedParams.cParams; assert(srcCCtx->appliedParams.useRowMatchFinder != ZSTD_paramSwitch_e.ZSTD_ps_auto); assert(srcCCtx->appliedParams.postBlockSplitter != ZSTD_paramSwitch_e.ZSTD_ps_auto); - assert( - srcCCtx->appliedParams.ldmParams.enableLdm != ZSTD_paramSwitch_e.ZSTD_ps_auto - ); + assert(srcCCtx->appliedParams.ldmParams.enableLdm != ZSTD_paramSwitch_e.ZSTD_ps_auto); @params.useRowMatchFinder = srcCCtx->appliedParams.useRowMatchFinder; @params.postBlockSplitter = srcCCtx->appliedParams.postBlockSplitter; @params.ldmParams = srcCCtx->appliedParams.ldmParams; @@ -3591,23 +3460,19 @@ public static unsafe partial class Methods zbuff ); assert( - dstCCtx->appliedParams.cParams.windowLog - == srcCCtx->appliedParams.cParams.windowLog + dstCCtx->appliedParams.cParams.windowLog == srcCCtx->appliedParams.cParams.windowLog ); assert( - dstCCtx->appliedParams.cParams.strategy - == srcCCtx->appliedParams.cParams.strategy + dstCCtx->appliedParams.cParams.strategy == srcCCtx->appliedParams.cParams.strategy ); assert( dstCCtx->appliedParams.cParams.hashLog == srcCCtx->appliedParams.cParams.hashLog ); assert( - dstCCtx->appliedParams.cParams.chainLog - == srcCCtx->appliedParams.cParams.chainLog + dstCCtx->appliedParams.cParams.chainLog == srcCCtx->appliedParams.cParams.chainLog ); assert( - dstCCtx->blockState.matchState.hashLog3 - == srcCCtx->blockState.matchState.hashLog3 + dstCCtx->blockState.matchState.hashLog3 == srcCCtx->blockState.matchState.hashLog3 ); } @@ -3889,7 +3754,7 @@ public static unsafe partial class Methods ); assert( SymbolEncodingType_e.set_basic < SymbolEncodingType_e.set_compressed - && SymbolEncodingType_e.set_rle < SymbolEncodingType_e.set_compressed + && SymbolEncodingType_e.set_rle < SymbolEncodingType_e.set_compressed ); assert( !( @@ -4098,8 +3963,7 @@ public static unsafe partial class Methods { nuint numSequences = (nuint)(seqStorePtr->sequences - seqStorePtr->sequencesStart); /* Base suspicion of uncompressibility on ratio of literals to sequences */ - int suspectUncompressible = - numSequences == 0 || litSize / numSequences >= 20 ? 1 : 0; + int suspectUncompressible = numSequences == 0 || litSize / numSequences >= 20 ? 1 : 0; nuint cSize = ZSTD_compressLiterals( op, dstCapacity, @@ -4471,9 +4335,7 @@ public static unsafe partial class Methods if (nbExternalSeqs == outSeqsCapacity) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_sequenceProducer_failed) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_sequenceProducer_failed)); } outSeqs[nbExternalSeqs] = new ZSTD_Sequence(); @@ -4490,8 +4352,8 @@ public static unsafe partial class Methods private static nuint ZSTD_fastSequenceLengthSum(ZSTD_Sequence* seqBuf, nuint seqBufSize) { nuint matchLenSum, - litLenSum, - i; + litLenSum, + i; matchLenSum = 0; litLenSum = 0; for (i = 0; i < seqBufSize; i++) @@ -4549,11 +4411,7 @@ public static unsafe partial class Methods if (curr > ms->nextToUpdate + 384) ms->nextToUpdate = curr - - ( - 192 < curr - ms->nextToUpdate - 384 - ? 192 - : curr - ms->nextToUpdate - 384 - ); + - (192 < curr - ms->nextToUpdate - 384 ? 192 : curr - ms->nextToUpdate - 384); } { @@ -4567,15 +4425,11 @@ public static unsafe partial class Methods if (zc->externSeqStore.pos < zc->externSeqStore.size) { - assert( - zc->appliedParams.ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_disable - ); + assert(zc->appliedParams.ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_disable); if (ZSTD_hasExtSeqProd(&zc->appliedParams) != 0) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_parameter_combination_unsupported - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_combination_unsupported) ); } @@ -4596,9 +4450,7 @@ public static unsafe partial class Methods if (ZSTD_hasExtSeqProd(&zc->appliedParams) != 0) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_parameter_combination_unsupported - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_combination_unsupported) ); } @@ -4648,7 +4500,7 @@ public static unsafe partial class Methods int, nuint, nuint>) - zc->appliedParams.extSeqProdFunc + zc->appliedParams.extSeqProdFunc )( zc->appliedParams.extSeqProdState, zc->extSeqBuf, @@ -4681,9 +4533,7 @@ public static unsafe partial class Methods if (seqLenSum > srcSize) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) ); } @@ -4916,9 +4766,7 @@ public static unsafe partial class Methods if (targetCBlockSize != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); } } @@ -4938,9 +4786,7 @@ public static unsafe partial class Methods if (nbWorkers != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); } } @@ -5102,9 +4948,7 @@ public static unsafe partial class Methods } { - nuint minLitSize = (nuint)( - prevHuf->repeatMode == HUF_repeat.HUF_repeat_valid ? 6 : 63 - ); + nuint minLitSize = (nuint)(prevHuf->repeatMode == HUF_repeat.HUF_repeat_valid ? 6 : 63); if (srcSize <= minLitSize) { hufMetadata->hType = SymbolEncodingType_e.set_basic; @@ -5204,10 +5048,7 @@ public static unsafe partial class Methods countWksp, maxSymbolValue ); - if ( - oldCSize < srcSize - && (oldCSize <= hSize + newCSize || hSize + 12 >= srcSize) - ) + if (oldCSize < srcSize && (oldCSize <= hSize + newCSize || hSize + 12 >= srcSize)) { memcpy(nextHuf, prevHuf, (uint)sizeof(ZSTD_hufCTables_t)); hufMetadata->hType = SymbolEncodingType_e.set_repeat; @@ -5322,8 +5163,7 @@ public static unsafe partial class Methods ) { nuint litSize = (nuint)(seqStorePtr->lit - seqStorePtr->litStart); - int huf_useOptDepth = - cctxParams->cParams.strategy >= ZSTD_strategy.ZSTD_btultra ? 1 : 0; + int huf_useOptDepth = cctxParams->cParams.strategy >= ZSTD_strategy.ZSTD_btultra ? 1 : 0; int hufFlags = huf_useOptDepth != 0 ? (int)HUF_flags_e.HUF_flags_optimalDepth : 0; entropyMetadata->hufMetadata.hufDesSize = ZSTD_buildBlockEntropyStats_literals( seqStorePtr->litStart, @@ -5899,11 +5739,9 @@ public static unsafe partial class Methods } if ( - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode - == FSE_repeat.FSE_repeat_valid + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat.FSE_repeat_valid ) - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = - FSE_repeat.FSE_repeat_check; + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat.FSE_repeat_check; return cSize; } @@ -6284,11 +6122,9 @@ public static unsafe partial class Methods } if ( - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode - == FSE_repeat.FSE_repeat_valid + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat.FSE_repeat_valid ) - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = - FSE_repeat.FSE_repeat_check; + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat.FSE_repeat_check; return cSize; } @@ -6322,10 +6158,7 @@ public static unsafe partial class Methods srcSize, lastBlock ); - if ( - cSize - != unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)) - ) + if (cSize != unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall))) { nuint maxCSize = srcSize - ZSTD_minGain(srcSize, zc->appliedParams.cParams.strategy); @@ -6386,11 +6219,9 @@ public static unsafe partial class Methods } if ( - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode - == FSE_repeat.FSE_repeat_valid + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode == FSE_repeat.FSE_repeat_valid ) - zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = - FSE_repeat.FSE_repeat_check; + zc->blockState.prevCBlock->entropy.fse.offcode_repeatMode = FSE_repeat.FSE_repeat_check; return cSize; } @@ -6429,13 +6260,13 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_splitLevels => - new int[10] { 0, 0, 1, 2, 2, 3, 3, 4, 4, 4 }; - private static int* splitLevels => - (int*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_splitLevels) - ); + private static ReadOnlySpan Span_splitLevels => + new int[10] { 0, 0, 1, 2, 2, 3, 3, 4, 4, 4 }; + private static int* splitLevels => + (int*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_splitLevels) + ); #else private static readonly int* splitLevels = GetArrayPointer( @@ -6627,11 +6458,11 @@ public static unsafe partial class Methods uint cBlockHeader = cSize == 1 ? lastBlock - + ((uint)blockType_e.bt_rle << 1) - + (uint)(blockSize << 3) + + ((uint)blockType_e.bt_rle << 1) + + (uint)(blockSize << 3) : lastBlock - + ((uint)blockType_e.bt_compressed << 1) - + (uint)(cSize << 3); + + ((uint)blockType_e.bt_compressed << 1) + + (uint)(cSize << 3); MEM_writeLE24(op, cBlockHeader); cSize += ZSTD_blockHeaderSize; } @@ -6676,17 +6507,15 @@ public static unsafe partial class Methods uint fcsCode = (uint)( @params->fParams.contentSizeFlag != 0 ? (pledgedSrcSize >= 256 ? 1 : 0) - + (pledgedSrcSize >= 65536 + 256 ? 1 : 0) - + (pledgedSrcSize >= 0xFFFFFFFFU ? 1 : 0) + + (pledgedSrcSize >= 65536 + 256 ? 1 : 0) + + (pledgedSrcSize >= 0xFFFFFFFFU ? 1 : 0) : 0 ); byte frameHeaderDescriptionByte = (byte)( dictIDSizeCode + (checksumFlag << 2) + (singleSegment << 5) + (fcsCode << 6) ); nuint pos = 0; - assert( - !(@params->fParams.contentSizeFlag != 0 && pledgedSrcSize == unchecked(0UL - 1)) - ); + assert(!(@params->fParams.contentSizeFlag != 0 && pledgedSrcSize == unchecked(0UL - 1))); if (dstCapacity < 18) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); @@ -6813,16 +6642,12 @@ public static unsafe partial class Methods * NOTE: seqs are not verified! Invalid sequences can cause out-of-bounds memory * access and data corruption. */ - private static void ZSTD_referenceExternalSequences( - ZSTD_CCtx_s* cctx, - rawSeq* seq, - nuint nbSeq - ) + private static void ZSTD_referenceExternalSequences(ZSTD_CCtx_s* cctx, rawSeq* seq, nuint nbSeq) { assert(cctx->stage == ZSTD_compressionStage_e.ZSTDcs_init); assert( nbSeq == 0 - || cctx->appliedParams.ldmParams.enableLdm != ZSTD_paramSwitch_e.ZSTD_ps_enable + || cctx->appliedParams.ldmParams.enableLdm != ZSTD_paramSwitch_e.ZSTD_ps_enable ); cctx->externSeqStore.seq = seq; cctx->externSeqStore.size = nbSeq; @@ -6898,14 +6723,7 @@ public static unsafe partial class Methods { nuint cSize = frame != 0 - ? ZSTD_compress_frameChunk( - cctx, - dst, - dstCapacity, - src, - srcSize, - lastFrameChunk - ) + ? ZSTD_compress_frameChunk(cctx, dst, dstCapacity, src, srcSize, lastFrameChunk) : ZSTD_compressBlock_internal(cctx, dst, dstCapacity, src, srcSize, 0); { nuint err_code = cSize; @@ -7022,9 +6840,7 @@ public static unsafe partial class Methods byte* ip = (byte*)src; byte* iend = ip + srcSize; int loadLdmDict = - @params->ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable && ls != null - ? 1 - : 0; + @params->ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable && ls != null ? 1 : 0; ZSTD_assertEqualCParams(@params->cParams, ms->cParams); { /* Allow the dictionary to set indices up to exactly ZSTD_CURRENT_MAX. @@ -7054,10 +6870,7 @@ public static unsafe partial class Methods } } - if ( - srcSize - > unchecked((uint)-1) - (MEM_64bits ? 3500U * (1 << 20) : 2000U * (1 << 20)) - ) + if (srcSize > unchecked((uint)-1) - (MEM_64bits ? 3500U * (1 << 20) : 2000U * (1 << 20))) { assert(ZSTD_window_isEmpty(ms->window) != 0); #if DEBUG @@ -7258,7 +7071,7 @@ public static unsafe partial class Methods { short* matchlengthNCount = stackalloc short[53]; uint matchlengthMaxValue = 52, - matchlengthLog; + matchlengthLog; nuint matchlengthHeaderSize = FSE_readNCount( matchlengthNCount, &matchlengthMaxValue, @@ -7303,7 +7116,7 @@ public static unsafe partial class Methods { short* litlengthNCount = stackalloc short[36]; uint litlengthMaxValue = 35, - litlengthLog; + litlengthLog; nuint litlengthHeaderSize = FSE_readNCount( litlengthNCount, &litlengthMaxValue, @@ -7487,16 +7300,7 @@ public static unsafe partial class Methods { if (dictContentType == ZSTD_dictContentType_e.ZSTD_dct_auto) { - return ZSTD_loadDictionaryContent( - ms, - ls, - ws, - @params, - dict, - dictSize, - dtlm, - tfp - ); + return ZSTD_loadDictionaryContent(ms, ls, ws, @params, dict, dictSize, dtlm, tfp); } if (dictContentType == ZSTD_dictContentType_e.ZSTD_dct_fullDict) @@ -7507,17 +7311,7 @@ public static unsafe partial class Methods assert(0 != 0); } - return ZSTD_loadZstdDictionary( - bs, - ms, - ws, - @params, - dict, - dictSize, - dtlm, - tfp, - workspace - ); + return ZSTD_loadZstdDictionary(bs, ms, ws, @params, dict, dictSize, dtlm, tfp, workspace); } /*! ZSTD_compressBegin_internal() : @@ -7795,15 +7589,7 @@ public static unsafe partial class Methods ) { nuint endResult; - nuint cSize = ZSTD_compressContinue_internal( - cctx, - dst, - dstCapacity, - src, - srcSize, - 1, - 1 - ); + nuint cSize = ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1, 1); { nuint err_code = cSize; if (ERR_isError(err_code)) @@ -7822,10 +7608,7 @@ public static unsafe partial class Methods } assert( - !( - cctx->appliedParams.fParams.contentSizeFlag != 0 - && cctx->pledgedSrcSizePlusOne == 0 - ) + !(cctx->appliedParams.fParams.contentSizeFlag != 0 && cctx->pledgedSrcSizePlusOne == 0) ); if (cctx->pledgedSrcSizePlusOne != 0) { @@ -8032,18 +7815,18 @@ public static unsafe partial class Methods ) { return ZSTD_cwksp_alloc_size((nuint)sizeof(ZSTD_CDict_s)) - + ZSTD_cwksp_alloc_size((8 << 10) + 512) - + ZSTD_sizeof_matchState( - &cParams, - ZSTD_resolveRowMatchFinderMode(ZSTD_paramSwitch_e.ZSTD_ps_auto, &cParams), - 1, - 0 - ) - + ( - dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef - ? 0 - : ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(dictSize, (nuint)sizeof(void*))) - ); + + ZSTD_cwksp_alloc_size((8 << 10) + 512) + + ZSTD_sizeof_matchState( + &cParams, + ZSTD_resolveRowMatchFinderMode(ZSTD_paramSwitch_e.ZSTD_ps_auto, &cParams), + 1, + 0 + ) + + ( + dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef + ? 0 + : ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(dictSize, (nuint)sizeof(void*))) + ); } /*! ZSTD_estimate?DictSize() : @@ -8071,7 +7854,7 @@ public static unsafe partial class Methods if (cdict == null) return 0; return (nuint)(cdict->workspace.workspace == cdict ? 0 : sizeof(ZSTD_CDict_s)) - + ZSTD_cwksp_sizeof(&cdict->workspace); + + ZSTD_cwksp_sizeof(&cdict->workspace); } private static nuint ZSTD_initCDict_internal( @@ -8174,27 +7957,17 @@ public static unsafe partial class Methods ZSTD_customMem customMem ) { - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; { nuint workspaceSize = ZSTD_cwksp_alloc_size((nuint)sizeof(ZSTD_CDict_s)) + ZSTD_cwksp_alloc_size((8 << 10) + 512) - + ZSTD_sizeof_matchState( - &cParams, - useRowMatchFinder, - enableDedicatedDictSearch, - 0 - ) + + ZSTD_sizeof_matchState(&cParams, useRowMatchFinder, enableDedicatedDictSearch, 0) + ( dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef ? 0 - : ZSTD_cwksp_alloc_size( - ZSTD_cwksp_align(dictSize, (nuint)sizeof(void*)) - ) + : ZSTD_cwksp_alloc_size(ZSTD_cwksp_align(dictSize, (nuint)sizeof(void*))) ); void* workspace = ZSTD_customMalloc(workspaceSize, customMem); ZSTD_cwksp ws; @@ -8260,17 +8033,11 @@ public static unsafe partial class Methods ZSTD_CCtx_params_s cctxParams = *originalCctxParams; ZSTD_compressionParameters cParams; ZSTD_CDict_s* cdict; - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; if (cctxParams.enableDedicatedDictSearch != 0) { - cParams = ZSTD_dedicatedDictSearch_getCParams( - cctxParams.compressionLevel, - dictSize - ); + cParams = ZSTD_dedicatedDictSearch_getCParams(cctxParams.compressionLevel, dictSize); ZSTD_overrideCParams(&cParams, &cctxParams.cParams); } else @@ -8340,11 +8107,7 @@ public static unsafe partial class Methods * in which case the only thing that it transports is the @compressionLevel. * This can be useful in a pipeline featuring ZSTD_compress_usingCDict() exclusively, * expecting a ZSTD_CDict parameter with any data, including those without a known dictionary. */ - public static ZSTD_CDict_s* ZSTD_createCDict( - void* dict, - nuint dictSize, - int compressionLevel - ) + public static ZSTD_CDict_s* ZSTD_createCDict(void* dict, nuint dictSize, int compressionLevel) { ZSTD_compressionParameters cParams = ZSTD_getCParams_internal( compressionLevel, @@ -8550,8 +8313,7 @@ public static unsafe partial class Methods if (pledgedSrcSize != unchecked(0UL - 1)) { uint limitedSrcSize = (uint)(pledgedSrcSize < 1U << 19 ? pledgedSrcSize : 1U << 19); - uint limitedSrcLog = - limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1; + uint limitedSrcLog = limitedSrcSize > 1 ? ZSTD_highbit32(limitedSrcSize - 1) + 1 : 1; cctxParams.cParams.windowLog = cctxParams.cParams.windowLog > limitedSrcLog ? cctxParams.cParams.windowLog @@ -8621,12 +8383,7 @@ public static unsafe partial class Methods { { /* will check if cdict != NULL */ - nuint err_code = ZSTD_compressBegin_usingCDict_internal( - cctx, - cdict, - fParams, - srcSize - ); + nuint err_code = ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, srcSize); if (ERR_isError(err_code)) { return err_code; @@ -8994,11 +8751,7 @@ public static unsafe partial class Methods * "0" also disables frame content size field. It may be enabled in the future. * This prototype will generate compilation warnings. */ - public static nuint ZSTD_initCStream_srcSize( - ZSTD_CCtx_s* zcs, - int compressionLevel, - ulong pss - ) + public static nuint ZSTD_initCStream_srcSize(ZSTD_CCtx_s* zcs, int compressionLevel, ulong pss) { /* temporary : 0 interpreted as "unknown" during transition period. * Users willing to specify "unknown" **must** use ZSTD_CONTENTSIZE_UNKNOWN. @@ -9171,8 +8924,7 @@ public static unsafe partial class Methods flushMode == ZSTD_EndDirective.ZSTD_e_end && ( (nuint)(oend - op) >= ZSTD_compressBound((nuint)(iend - ip)) - || zcs->appliedParams.outBufferMode - == ZSTD_bufferMode_e.ZSTD_bm_stable + || zcs->appliedParams.outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_stable ) && zcs->inBuffPos == 0 ) @@ -9233,9 +8985,7 @@ public static unsafe partial class Methods } else { - assert( - zcs->appliedParams.inBufferMode == ZSTD_bufferMode_e.ZSTD_bm_stable - ); + assert(zcs->appliedParams.inBufferMode == ZSTD_bufferMode_e.ZSTD_bm_stable); if ( flushMode == ZSTD_EndDirective.ZSTD_e_continue && (nuint)(iend - ip) < zcs->blockSizeMax @@ -9254,158 +9004,149 @@ public static unsafe partial class Methods } } - { - int inputBuffered = - zcs->appliedParams.inBufferMode - == ZSTD_bufferMode_e.ZSTD_bm_buffered - ? 1 - : 0; - void* cDst; - nuint cSize; - nuint oSize = (nuint)(oend - op); - nuint iSize = - inputBuffered != 0 ? zcs->inBuffPos - zcs->inToCompress - : (nuint)(iend - ip) < zcs->blockSizeMax ? (nuint)(iend - ip) - : zcs->blockSizeMax; - if ( - oSize >= ZSTD_compressBound(iSize) - || zcs->appliedParams.outBufferMode - == ZSTD_bufferMode_e.ZSTD_bm_stable - ) - cDst = op; - else { - cDst = zcs->outBuff; - oSize = zcs->outBuffSize; - } - - if (inputBuffered != 0) - { - uint lastBlock = - flushMode == ZSTD_EndDirective.ZSTD_e_end && ip == iend - ? 1U - : 0U; - cSize = - lastBlock != 0 - ? ZSTD_compressEnd_public( - zcs, - cDst, - oSize, - zcs->inBuff + zcs->inToCompress, - iSize - ) - : ZSTD_compressContinue_public( - zcs, - cDst, - oSize, - zcs->inBuff + zcs->inToCompress, - iSize - ); + int inputBuffered = + zcs->appliedParams.inBufferMode == ZSTD_bufferMode_e.ZSTD_bm_buffered + ? 1 + : 0; + void* cDst; + nuint cSize; + nuint oSize = (nuint)(oend - op); + nuint iSize = + inputBuffered != 0 ? zcs->inBuffPos - zcs->inToCompress + : (nuint)(iend - ip) < zcs->blockSizeMax ? (nuint)(iend - ip) + : zcs->blockSizeMax; + if ( + oSize >= ZSTD_compressBound(iSize) + || zcs->appliedParams.outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_stable + ) + cDst = op; + else { - nuint err_code = cSize; - if (ERR_isError(err_code)) + cDst = zcs->outBuff; + oSize = zcs->outBuffSize; + } + + if (inputBuffered != 0) + { + uint lastBlock = + flushMode == ZSTD_EndDirective.ZSTD_e_end && ip == iend ? 1U : 0U; + cSize = + lastBlock != 0 + ? ZSTD_compressEnd_public( + zcs, + cDst, + oSize, + zcs->inBuff + zcs->inToCompress, + iSize + ) + : ZSTD_compressContinue_public( + zcs, + cDst, + oSize, + zcs->inBuff + zcs->inToCompress, + iSize + ); { - return err_code; + nuint err_code = cSize; + if (ERR_isError(err_code)) + { + return err_code; + } } - } - zcs->frameEnded = lastBlock; - zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSizeMax; - if (zcs->inBuffTarget > zcs->inBuffSize) - { - zcs->inBuffPos = 0; - zcs->inBuffTarget = zcs->blockSizeMax; - } + zcs->frameEnded = lastBlock; + zcs->inBuffTarget = zcs->inBuffPos + zcs->blockSizeMax; + if (zcs->inBuffTarget > zcs->inBuffSize) + { + zcs->inBuffPos = 0; + zcs->inBuffTarget = zcs->blockSizeMax; + } #if DEBUG - if (lastBlock == 0) - assert(zcs->inBuffTarget <= zcs->inBuffSize); + if (lastBlock == 0) + assert(zcs->inBuffTarget <= zcs->inBuffSize); #endif - zcs->inToCompress = zcs->inBuffPos; - } - else - { - uint lastBlock = - flushMode == ZSTD_EndDirective.ZSTD_e_end && ip + iSize == iend - ? 1U - : 0U; - cSize = - lastBlock != 0 - ? ZSTD_compressEnd_public(zcs, cDst, oSize, ip, iSize) - : ZSTD_compressContinue_public(zcs, cDst, oSize, ip, iSize); - if (ip != null) - ip += iSize; + zcs->inToCompress = zcs->inBuffPos; + } + else { - nuint err_code = cSize; - if (ERR_isError(err_code)) + uint lastBlock = + flushMode == ZSTD_EndDirective.ZSTD_e_end && ip + iSize == iend + ? 1U + : 0U; + cSize = + lastBlock != 0 + ? ZSTD_compressEnd_public(zcs, cDst, oSize, ip, iSize) + : ZSTD_compressContinue_public(zcs, cDst, oSize, ip, iSize); + if (ip != null) + ip += iSize; { - return err_code; + nuint err_code = cSize; + if (ERR_isError(err_code)) + { + return err_code; + } } - } - zcs->frameEnded = lastBlock; + zcs->frameEnded = lastBlock; #if DEBUG - if (lastBlock != 0) - assert(ip == iend); + if (lastBlock != 0) + assert(ip == iend); #endif - } - - if (cDst == op) - { - op += cSize; - if (zcs->frameEnded != 0) - { - someMoreWork = 0; - ZSTD_CCtx_reset( - zcs, - ZSTD_ResetDirective.ZSTD_reset_session_only - ); } - break; - } + if (cDst == op) + { + op += cSize; + if (zcs->frameEnded != 0) + { + someMoreWork = 0; + ZSTD_CCtx_reset(zcs, ZSTD_ResetDirective.ZSTD_reset_session_only); + } - zcs->outBuffContentSize = cSize; - zcs->outBuffFlushedSize = 0; - zcs->streamStage = ZSTD_cStreamStage.zcss_flush; - } + break; + } + + zcs->outBuffContentSize = cSize; + zcs->outBuffFlushedSize = 0; + zcs->streamStage = ZSTD_cStreamStage.zcss_flush; + } goto case ZSTD_cStreamStage.zcss_flush; case ZSTD_cStreamStage.zcss_flush: - assert( - zcs->appliedParams.outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_buffered - ); + assert(zcs->appliedParams.outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_buffered); - { - nuint toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; - nuint flushed = ZSTD_limitCopy( - op, - (nuint)(oend - op), - zcs->outBuff + zcs->outBuffFlushedSize, - toFlush - ); - if (flushed != 0) - op += flushed; - zcs->outBuffFlushedSize += flushed; - if (toFlush != flushed) { - assert(op == oend); - someMoreWork = 0; + nuint toFlush = zcs->outBuffContentSize - zcs->outBuffFlushedSize; + nuint flushed = ZSTD_limitCopy( + op, + (nuint)(oend - op), + zcs->outBuff + zcs->outBuffFlushedSize, + toFlush + ); + if (flushed != 0) + op += flushed; + zcs->outBuffFlushedSize += flushed; + if (toFlush != flushed) + { + assert(op == oend); + someMoreWork = 0; + break; + } + + zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; + if (zcs->frameEnded != 0) + { + someMoreWork = 0; + ZSTD_CCtx_reset(zcs, ZSTD_ResetDirective.ZSTD_reset_session_only); + break; + } + + zcs->streamStage = ZSTD_cStreamStage.zcss_load; break; } - zcs->outBuffContentSize = zcs->outBuffFlushedSize = 0; - if (zcs->frameEnded != 0) - { - someMoreWork = 0; - ZSTD_CCtx_reset(zcs, ZSTD_ResetDirective.ZSTD_reset_session_only); - break; - } - - zcs->streamStage = ZSTD_cStreamStage.zcss_load; - break; - } - default: assert(0 != 0); break; @@ -9601,9 +9342,7 @@ public static unsafe partial class Methods ); if (cctx->mtctx == null) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); } } @@ -9715,18 +9454,14 @@ public static unsafe partial class Methods if (input->src != cctx->expectedInBuffer.src) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_stabilityCondition_notRespected - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_stabilityCondition_notRespected) ); } if (input->pos != cctx->expectedInBuffer.size) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_stabilityCondition_notRespected - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_stabilityCondition_notRespected) ); } } @@ -9734,9 +9469,7 @@ public static unsafe partial class Methods input->pos = input->size; cctx->expectedInBuffer = *input; cctx->stableIn_notConsumed += inputSize; - return (nuint)( - cctx->requestedParams.format == ZSTD_format_e.ZSTD_f_zstd1 ? 6 : 2 - ); + return (nuint)(cctx->requestedParams.format == ZSTD_format_e.ZSTD_f_zstd1 ? 6 : 2); } { @@ -9783,10 +9516,7 @@ public static unsafe partial class Methods flushMin = ZSTDMT_compressStream_generic(cctx->mtctx, output, input, endOp); cctx->consumedSrcSize += input->pos - ipos; cctx->producedCSize += output->pos - opos; - if ( - ERR_isError(flushMin) - || endOp == ZSTD_EndDirective.ZSTD_e_end && flushMin == 0 - ) + if (ERR_isError(flushMin) || endOp == ZSTD_EndDirective.ZSTD_e_end && flushMin == 0) { if (flushMin == 0) ZSTD_CCtx_trace(cctx, 0); @@ -9815,7 +9545,7 @@ public static unsafe partial class Methods { assert( endOp == ZSTD_EndDirective.ZSTD_e_flush - || endOp == ZSTD_EndDirective.ZSTD_e_end + || endOp == ZSTD_EndDirective.ZSTD_e_end ); if (flushMin == 0 || output->pos == output->size) break; @@ -9824,8 +9554,8 @@ public static unsafe partial class Methods assert( endOp == ZSTD_EndDirective.ZSTD_e_continue - || flushMin == 0 - || output->pos == output->size + || flushMin == 0 + || output->pos == output->size ); ZSTD_setBufferExpectations(cctx, output, input); return flushMin; @@ -9969,9 +9699,7 @@ public static unsafe partial class Methods if (matchLength < matchLenLowerBound) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } return 0; @@ -10046,11 +9774,7 @@ public static unsafe partial class Methods } memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, (uint)sizeof(repcodes_s)); - for ( - ; - idx < inSeqsSize && (inSeqs[idx].matchLength != 0 || inSeqs[idx].offset != 0); - ++idx - ) + for (; idx < inSeqsSize && (inSeqs[idx].matchLength != 0 || inSeqs[idx].offset != 0); ++idx) { uint litLength = inSeqs[idx].litLength; uint matchLength = inSeqs[idx].matchLength; @@ -10100,9 +9824,7 @@ public static unsafe partial class Methods if (idx == inSeqsSize) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } assert(externalRepSearch != ZSTD_paramSwitch_e.ZSTD_ps_auto); @@ -10143,9 +9865,7 @@ public static unsafe partial class Methods if (ip != iend) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } seqPos->idx = idx + 1; @@ -10302,8 +10022,7 @@ public static unsafe partial class Methods } assert( - idx == inSeqsSize - || endPosInSequence <= inSeqs[idx].litLength + inSeqs[idx].matchLength + idx == inSeqsSize || endPosInSequence <= inSeqs[idx].litLength + inSeqs[idx].matchLength ); seqPos->idx = idx; seqPos->posInSequence = endPosInSequence; @@ -10382,9 +10101,7 @@ public static unsafe partial class Methods } if (end == 0) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); return blockSize; } @@ -10793,9 +10510,7 @@ public static unsafe partial class Methods nuint seqNb = 0; if (nbSequences >= cctx->seqStore.maxNbSeq) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } memcpy(updatedRepcodes.rep, cctx->blockState.prevCBlock->rep, (uint)sizeof(repcodes_s)); @@ -10821,8 +10536,7 @@ public static unsafe partial class Methods else { assert(longl <= 2 * (nbSequences - 1)); - cctx->seqStore.longLengthType = - ZSTD_longLengthType_e.ZSTD_llt_literalLength; + cctx->seqStore.longLengthType = ZSTD_longLengthType_e.ZSTD_llt_literalLength; cctx->seqStore.longLengthPos = (uint)(longl - (nbSequences - 1) - 1); } } @@ -10834,11 +10548,7 @@ public static unsafe partial class Methods uint litLength = inSeqs[seqNb].litLength; uint matchLength = inSeqs[seqNb].matchLength; uint ll0 = litLength == 0 ? 1U : 0U; - uint offBase = ZSTD_finalizeOffBase( - inSeqs[seqNb].offset, - updatedRepcodes.rep, - ll0 - ); + uint offBase = ZSTD_finalizeOffBase(inSeqs[seqNb].offset, updatedRepcodes.rep, ll0); ZSTD_storeSeqOnly(&cctx->seqStore, litLength, offBase, matchLength); ZSTD_updateRep(updatedRepcodes.rep, offBase, ll0); } @@ -10928,14 +10638,10 @@ public static unsafe partial class Methods cctx->appliedParams.searchForExternalRepcodes == ZSTD_paramSwitch_e.ZSTD_ps_enable ? 1 : 0; - assert( - cctx->appliedParams.searchForExternalRepcodes != ZSTD_paramSwitch_e.ZSTD_ps_auto - ); + assert(cctx->appliedParams.searchForExternalRepcodes != ZSTD_paramSwitch_e.ZSTD_ps_auto); if (nbSequences == 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } if (nbSequences == 1 && inSeqs[0].litLength == 0) @@ -10956,8 +10662,8 @@ public static unsafe partial class Methods while (nbSequences != 0) { nuint compressedSeqsSize, - cBlockSize, - conversionStatus; + cBlockSize, + conversionStatus; BlockSummary block = ZSTD_get1BlockSummary(inSeqs, nbSequences); uint lastBlock = block.nbSequences == nbSequences ? 1U : 0U; { @@ -11062,16 +10768,12 @@ public static unsafe partial class Methods if (litSize != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } if (remaining != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_externalSequences_invalid)); } return cSize; @@ -11127,14 +10829,9 @@ public static unsafe partial class Methods } } - if ( - cctx->appliedParams.blockDelimiters - == ZSTD_sequenceFormat_e.ZSTD_sf_noBlockDelimiters - ) + if (cctx->appliedParams.blockDelimiters == ZSTD_sequenceFormat_e.ZSTD_sf_noBlockDelimiters) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported)); } if (cctx->appliedParams.validateSequences != 0) @@ -11144,9 +10841,7 @@ public static unsafe partial class Methods if (cctx->appliedParams.fParams.checksumFlag != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported)); } { @@ -11296,8 +10991,8 @@ public static unsafe partial class Methods && cParams->strategy <= ZSTD_strategy.ZSTD_lazy2 && cParams->hashLog > cParams->chainLog && cParams->chainLog <= 24 - ? 1 - : 0; + ? 1 + : 0; } /** @@ -11305,9 +11000,7 @@ public static unsafe partial class Methods * search. This is used to recover the params set to be used in the working * context. (Otherwise, those tables would also grow.) */ - private static void ZSTD_dedicatedDictSearch_revertCParams( - ZSTD_compressionParameters* cParams - ) + private static void ZSTD_dedicatedDictSearch_revertCParams(ZSTD_compressionParameters* cParams) { switch (cParams->strategy) { @@ -11529,4 +11222,4 @@ public static unsafe partial class Methods @params->extSeqProdState = null; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressInternal.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressInternal.cs index d41e50a7..2e836fb1 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressInternal.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressInternal.cs @@ -12,10 +12,7 @@ public static unsafe partial class Methods * indicated by longLengthPos and longLengthType, and adds MINMATCH back to matchLength. */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ZSTD_SequenceLength ZSTD_getSequenceLength( - SeqStore_t* seqStore, - SeqDef_s* seq - ) + private static ZSTD_SequenceLength ZSTD_getSequenceLength(SeqStore_t* seqStore, SeqDef_s* seq) { ZSTD_SequenceLength seqLen; seqLen.litLength = seq->litLength; @@ -44,79 +41,79 @@ public static unsafe partial class Methods capacity: 0 ); #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_LL_Code => - new byte[64] - { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 16, - 17, - 17, - 18, - 18, - 19, - 19, - 20, - 20, - 20, - 20, - 21, - 21, - 21, - 21, - 22, - 22, - 22, - 22, - 22, - 22, - 22, - 22, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 23, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - 24, - }; - private static byte* LL_Code => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_LL_Code) - ); + private static ReadOnlySpan Span_LL_Code => + new byte[64] + { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 16, + 17, + 17, + 18, + 18, + 19, + 19, + 20, + 20, + 20, + 20, + 21, + 21, + 21, + 21, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 22, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 23, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + 24, + }; + private static byte* LL_Code => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_LL_Code) + ); #else private static readonly byte* LL_Code = GetArrayPointer( @@ -198,143 +195,143 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_ML_Code => - new byte[128] - { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 32, - 33, - 33, - 34, - 34, - 35, - 35, - 36, - 36, - 36, - 36, - 37, - 37, - 37, - 37, - 38, - 38, - 38, - 38, - 38, - 38, - 38, - 38, - 39, - 39, - 39, - 39, - 39, - 39, - 39, - 39, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 40, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 41, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - 42, - }; - private static byte* ML_Code => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_ML_Code) - ); + private static ReadOnlySpan Span_ML_Code => + new byte[128] + { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 32, + 33, + 33, + 34, + 34, + 35, + 35, + 36, + 36, + 36, + 36, + 37, + 37, + 37, + 37, + 38, + 38, + 38, + 38, + 38, + 38, + 38, + 38, + 39, + 39, + 39, + 39, + 39, + 39, + 39, + 39, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 40, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 41, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + 42, + }; + private static byte* ML_Code => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_ML_Code) + ); #else private static readonly byte* ML_Code = GetArrayPointer( @@ -501,12 +498,7 @@ public static unsafe partial class Methods * @return index >= lowLimit ? candidate : backup, * tries to force branchless codegen. */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static byte* ZSTD_selectAddr( - uint index, - uint lowLimit, - byte* candidate, - byte* backup - ) + private static byte* ZSTD_selectAddr(uint index, uint lowLimit, byte* candidate, byte* backup) { return index >= lowLimit ? candidate : backup; } @@ -523,8 +515,7 @@ public static unsafe partial class Methods uint lastBlock ) { - uint cBlockHeader24 = - lastBlock + ((uint)blockType_e.bt_raw << 1) + (uint)(srcSize << 3); + uint cBlockHeader24 = lastBlock + ((uint)blockType_e.bt_raw << 1) + (uint)(srcSize << 3); if (srcSize + ZSTD_blockHeaderSize > dstCapacity) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); @@ -584,8 +575,8 @@ public static unsafe partial class Methods return cctxParams->cParams.strategy == ZSTD_strategy.ZSTD_fast && cctxParams->cParams.targetLength > 0 - ? 1 - : 0; + ? 1 + : 0; } } @@ -623,8 +614,7 @@ public static unsafe partial class Methods ) { assert( - (nuint)(seqStorePtr->sequences - seqStorePtr->sequencesStart) - < seqStorePtr->maxNbSeq + (nuint)(seqStorePtr->sequences - seqStorePtr->sequencesStart) < seqStorePtr->maxNbSeq ); assert(litLength <= 1 << 17); if (litLength > 0xFFFF) @@ -676,8 +666,7 @@ public static unsafe partial class Methods byte* litLimit_w = litLimit - 32; byte* litEnd = literals + litLength; assert( - (nuint)(seqStorePtr->sequences - seqStorePtr->sequencesStart) - < seqStorePtr->maxNbSeq + (nuint)(seqStorePtr->sequences - seqStorePtr->sequencesStart) < seqStorePtr->maxNbSeq ); assert(seqStorePtr->maxNbLit <= 128 * (1 << 10)); assert(seqStorePtr->lit + litLength <= seqStorePtr->litStart + seqStorePtr->maxNbLit); @@ -1052,10 +1041,9 @@ public static unsafe partial class Methods [MethodImpl(MethodImplOptions.AggressiveInlining)] private static uint ZSTD_window_isEmpty(ZSTD_window_t window) { - return - window.dictLimit == 2 && window.lowLimit == 2 && window.nextSrc - window.@base == 2 - ? 1U - : 0U; + return window.dictLimit == 2 && window.lowLimit == 2 && window.nextSrc - window.@base == 2 + ? 1U + : 0U; } /** @@ -1079,9 +1067,9 @@ public static unsafe partial class Methods return ZSTD_window_hasExtDict(ms->window) != 0 ? ZSTD_dictMode_e.ZSTD_extDict : ms->dictMatchState != null ? ms->dictMatchState->dedicatedDictSearch != 0 - ? ZSTD_dictMode_e.ZSTD_dedicatedDictSearch + ? ZSTD_dictMode_e.ZSTD_dedicatedDictSearch : ZSTD_dictMode_e.ZSTD_dictMatchState - : ZSTD_dictMode_e.ZSTD_noDict; + : ZSTD_dictMode_e.ZSTD_noDict; } /** @@ -1305,12 +1293,12 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_stringToByte_20_00 => new byte[] { 32, 0 }; - private static byte* stringToByte_20_00 => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_stringToByte_20_00) - ); + private static ReadOnlySpan Span_stringToByte_20_00 => new byte[] { 32, 0 }; + private static byte* stringToByte_20_00 => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_stringToByte_20_00) + ); #else private static readonly byte* stringToByte_20_00 = GetArrayPointer(new byte[] { 32, 0 }); @@ -1385,11 +1373,7 @@ public static unsafe partial class Methods * Returns the lowest allowed match index. It may either be in the ext-dict or the prefix. */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint ZSTD_getLowestMatchIndex( - ZSTD_MatchState_t* ms, - uint curr, - uint windowLog - ) + private static uint ZSTD_getLowestMatchIndex(ZSTD_MatchState_t* ms, uint curr, uint windowLog) { uint maxDistance = 1U << (int)windowLog; uint lowestValid = ms->window.lowLimit; @@ -1407,11 +1391,7 @@ public static unsafe partial class Methods * Returns the lowest allowed match index in the prefix. */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static uint ZSTD_getLowestPrefixIndex( - ZSTD_MatchState_t* ms, - uint curr, - uint windowLog - ) + private static uint ZSTD_getLowestPrefixIndex(ZSTD_MatchState_t* ms, uint curr, uint windowLog) { uint maxDistance = 1U << (int)windowLog; uint lowestValid = ms->window.dictLimit; diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressLiterals.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressLiterals.cs index 06fe5a4f..a4f92ab3 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressLiterals.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressLiterals.cs @@ -110,10 +110,7 @@ public static unsafe partial class Methods * for literal compression to even be attempted. * Minimum is made tighter as compression strategy increases. */ - private static nuint ZSTD_minLiteralsToCompress( - ZSTD_strategy strategy, - HUF_repeat huf_repeat - ) + private static nuint ZSTD_minLiteralsToCompress(ZSTD_strategy strategy, HUF_repeat huf_repeat) { assert((int)strategy >= 0); assert((int)strategy <= 9); @@ -276,40 +273,36 @@ public static unsafe partial class Methods assert(srcSize >= 6); #endif - { - uint lhc = - (uint)hType - + ((singleStream == 0 ? 1U : 0U) << 2) - + ((uint)srcSize << 4) - + ((uint)cLitSize << 14); - MEM_writeLE24(ostart, lhc); - break; - } + { + uint lhc = + (uint)hType + + ((singleStream == 0 ? 1U : 0U) << 2) + + ((uint)srcSize << 4) + + ((uint)cLitSize << 14); + MEM_writeLE24(ostart, lhc); + break; + } case 4: assert(srcSize >= 6); - { - uint lhc = - (uint)(hType + (2 << 2)) - + ((uint)srcSize << 4) - + ((uint)cLitSize << 18); - MEM_writeLE32(ostart, lhc); - break; - } + { + uint lhc = + (uint)(hType + (2 << 2)) + ((uint)srcSize << 4) + ((uint)cLitSize << 18); + MEM_writeLE32(ostart, lhc); + break; + } case 5: assert(srcSize >= 6); - { - uint lhc = - (uint)(hType + (3 << 2)) - + ((uint)srcSize << 4) - + ((uint)cLitSize << 22); - MEM_writeLE32(ostart, lhc); - ostart[4] = (byte)(cLitSize >> 10); - break; - } + { + uint lhc = + (uint)(hType + (3 << 2)) + ((uint)srcSize << 4) + ((uint)cLitSize << 22); + MEM_writeLE32(ostart, lhc); + ostart[4] = (byte)(cLitSize >> 10); + break; + } default: assert(0 != 0); @@ -318,4 +311,4 @@ public static unsafe partial class Methods return lhSize + cLitSize; } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSequences.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSequences.cs index 26650be8..e0fd5eee 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSequences.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSequences.cs @@ -7,271 +7,271 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_kInverseProbabilityLog256 => - new uint[256] - { - 0, - 2048, - 1792, - 1642, - 1536, - 1453, - 1386, - 1329, - 1280, - 1236, - 1197, - 1162, - 1130, - 1100, - 1073, - 1047, - 1024, - 1001, - 980, - 960, - 941, - 923, - 906, - 889, - 874, - 859, - 844, - 830, - 817, - 804, - 791, - 779, - 768, - 756, - 745, - 734, - 724, - 714, - 704, - 694, - 685, - 676, - 667, - 658, - 650, - 642, - 633, - 626, - 618, - 610, - 603, - 595, - 588, - 581, - 574, - 567, - 561, - 554, - 548, - 542, - 535, - 529, - 523, - 517, - 512, - 506, - 500, - 495, - 489, - 484, - 478, - 473, - 468, - 463, - 458, - 453, - 448, - 443, - 438, - 434, - 429, - 424, - 420, - 415, - 411, - 407, - 402, - 398, - 394, - 390, - 386, - 382, - 377, - 373, - 370, - 366, - 362, - 358, - 354, - 350, - 347, - 343, - 339, - 336, - 332, - 329, - 325, - 322, - 318, - 315, - 311, - 308, - 305, - 302, - 298, - 295, - 292, - 289, - 286, - 282, - 279, - 276, - 273, - 270, - 267, - 264, - 261, - 258, - 256, - 253, - 250, - 247, - 244, - 241, - 239, - 236, - 233, - 230, - 228, - 225, - 222, - 220, - 217, - 215, - 212, - 209, - 207, - 204, - 202, - 199, - 197, - 194, - 192, - 190, - 187, - 185, - 182, - 180, - 178, - 175, - 173, - 171, - 168, - 166, - 164, - 162, - 159, - 157, - 155, - 153, - 151, - 149, - 146, - 144, - 142, - 140, - 138, - 136, - 134, - 132, - 130, - 128, - 126, - 123, - 121, - 119, - 117, - 115, - 114, - 112, - 110, - 108, - 106, - 104, - 102, - 100, - 98, - 96, - 94, - 93, - 91, - 89, - 87, - 85, - 83, - 82, - 80, - 78, - 76, - 74, - 73, - 71, - 69, - 67, - 66, - 64, - 62, - 61, - 59, - 57, - 55, - 54, - 52, - 50, - 49, - 47, - 46, - 44, - 42, - 41, - 39, - 37, - 36, - 34, - 33, - 31, - 30, - 28, - 26, - 25, - 23, - 22, - 20, - 19, - 17, - 16, - 14, - 13, - 11, - 10, - 8, - 7, - 5, - 4, - 2, - 1, - }; - private static uint* kInverseProbabilityLog256 => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_kInverseProbabilityLog256) - ); + private static ReadOnlySpan Span_kInverseProbabilityLog256 => + new uint[256] + { + 0, + 2048, + 1792, + 1642, + 1536, + 1453, + 1386, + 1329, + 1280, + 1236, + 1197, + 1162, + 1130, + 1100, + 1073, + 1047, + 1024, + 1001, + 980, + 960, + 941, + 923, + 906, + 889, + 874, + 859, + 844, + 830, + 817, + 804, + 791, + 779, + 768, + 756, + 745, + 734, + 724, + 714, + 704, + 694, + 685, + 676, + 667, + 658, + 650, + 642, + 633, + 626, + 618, + 610, + 603, + 595, + 588, + 581, + 574, + 567, + 561, + 554, + 548, + 542, + 535, + 529, + 523, + 517, + 512, + 506, + 500, + 495, + 489, + 484, + 478, + 473, + 468, + 463, + 458, + 453, + 448, + 443, + 438, + 434, + 429, + 424, + 420, + 415, + 411, + 407, + 402, + 398, + 394, + 390, + 386, + 382, + 377, + 373, + 370, + 366, + 362, + 358, + 354, + 350, + 347, + 343, + 339, + 336, + 332, + 329, + 325, + 322, + 318, + 315, + 311, + 308, + 305, + 302, + 298, + 295, + 292, + 289, + 286, + 282, + 279, + 276, + 273, + 270, + 267, + 264, + 261, + 258, + 256, + 253, + 250, + 247, + 244, + 241, + 239, + 236, + 233, + 230, + 228, + 225, + 222, + 220, + 217, + 215, + 212, + 209, + 207, + 204, + 202, + 199, + 197, + 194, + 192, + 190, + 187, + 185, + 182, + 180, + 178, + 175, + 173, + 171, + 168, + 166, + 164, + 162, + 159, + 157, + 155, + 153, + 151, + 149, + 146, + 144, + 142, + 140, + 138, + 136, + 134, + 132, + 130, + 128, + 126, + 123, + 121, + 119, + 117, + 115, + 114, + 112, + 110, + 108, + 106, + 104, + 102, + 100, + 98, + 96, + 94, + 93, + 91, + 89, + 87, + 85, + 83, + 82, + 80, + 78, + 76, + 74, + 73, + 71, + 69, + 67, + 66, + 64, + 62, + 61, + 59, + 57, + 55, + 54, + 52, + 50, + 49, + 47, + 46, + 44, + 42, + 41, + 39, + 37, + 36, + 34, + 33, + 31, + 30, + 28, + 26, + 25, + 23, + 22, + 20, + 19, + 17, + 16, + 14, + 13, + 11, + 10, + 8, + 7, + 5, + 4, + 2, + 1, + }; + private static uint* kInverseProbabilityLog256 => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_kInverseProbabilityLog256) + ); #else private static readonly uint* kInverseProbabilityLog256 = GetArrayPointer( @@ -641,12 +641,7 @@ public static unsafe partial class Methods * table described by norm. The max symbol support by norm is assumed >= max. * norm must be valid for every symbol with non-zero probability in count. */ - private static nuint ZSTD_crossEntropyCost( - short* norm, - uint accuracyLog, - uint* count, - uint max - ) + private static nuint ZSTD_crossEntropyCost(short* norm, uint accuracyLog, uint* count, uint max) { uint shift = 8 - accuracyLog; nuint cost = 0; @@ -732,16 +727,12 @@ public static unsafe partial class Methods if (isDefaultAllowed != default) { assert(!ERR_isError(basicCost)); - assert( - !(*repeatMode == FSE_repeat.FSE_repeat_valid && ERR_isError(repeatCost)) - ); + assert(!(*repeatMode == FSE_repeat.FSE_repeat_valid && ERR_isError(repeatCost))); } #endif assert(!ERR_isError(NCountCost)); - assert( - compressedCost < unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxCode)) - ); + assert(compressedCost < unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_maxCode))); if (basicCost <= repeatCost && basicCost <= compressedCost) { assert(isDefaultAllowed != default); @@ -786,13 +777,13 @@ public static unsafe partial class Methods switch (type) { case SymbolEncodingType_e.set_rle: - { - nuint err_code = FSE_buildCTable_rle(nextCTable, (byte)max); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = FSE_buildCTable_rle(nextCTable, (byte)max); + if (ERR_isError(err_code)) + { + return err_code; + } } - } if (dstCapacity == 0) { @@ -805,21 +796,21 @@ public static unsafe partial class Methods memcpy(nextCTable, prevCTable, (uint)prevCTableSize); return 0; case SymbolEncodingType_e.set_basic: - { - /* note : could be pre-calculated */ - nuint err_code = FSE_buildCTable_wksp( - nextCTable, - defaultNorm, - defaultMax, - defaultNormLog, - entropyWorkspace, - entropyWorkspaceSize - ); - if (ERR_isError(err_code)) { - return err_code; + /* note : could be pre-calculated */ + nuint err_code = FSE_buildCTable_wksp( + nextCTable, + defaultNorm, + defaultMax, + defaultNormLog, + entropyWorkspace, + entropyWorkspaceSize + ); + if (ERR_isError(err_code)) + { + return err_code; + } } - } return 0; case SymbolEncodingType_e.set_compressed: diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSuperblock.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSuperblock.cs index bc5dcbda..8a79453b 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSuperblock.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCompressSuperblock.cs @@ -61,7 +61,7 @@ public static unsafe partial class Methods assert(litSize > 0); assert( hufMetadata->hType == SymbolEncodingType_e.set_compressed - || hufMetadata->hType == SymbolEncodingType_e.set_repeat + || hufMetadata->hType == SymbolEncodingType_e.set_repeat ); if (writeEntropy != 0 && hufMetadata->hType == SymbolEncodingType_e.set_compressed) { @@ -105,9 +105,7 @@ public static unsafe partial class Methods if ( lhSize < (nuint)( - 3 - + (cLitSize >= 1 * (1 << 10) ? 1 : 0) - + (cLitSize >= 16 * (1 << 10) ? 1 : 0) + 3 + (cLitSize >= 1 * (1 << 10) ? 1 : 0) + (cLitSize >= 16 * (1 << 10) ? 1 : 0) ) ) { @@ -131,16 +129,14 @@ public static unsafe partial class Methods case 4: { - uint lhc = - (uint)(hType + (2 << 2)) + ((uint)litSize << 4) + ((uint)cLitSize << 18); + uint lhc = (uint)(hType + (2 << 2)) + ((uint)litSize << 4) + ((uint)cLitSize << 18); MEM_writeLE32(ostart, lhc); break; } case 5: { - uint lhc = - (uint)(hType + (3 << 2)) + ((uint)litSize << 4) + ((uint)cLitSize << 22); + uint lhc = (uint)(hType + (3 << 2)) + ((uint)litSize << 4) + ((uint)cLitSize << 22); MEM_writeLE32(ostart, lhc); ostart[4] = (byte)(cLitSize >> 10); break; @@ -617,7 +613,7 @@ public static unsafe partial class Methods private static nuint countLiterals(SeqStore_t* seqStore, SeqDef_s* sp, nuint seqCount) { nuint n, - total = 0; + total = 0; assert(sp != null); for (n = 0; n < seqCount; n++) { @@ -637,8 +633,8 @@ public static unsafe partial class Methods ) { nuint n, - budget = 0, - inSize = 0; + budget = 0, + inSize = 0; /* generous estimate */ nuint headerSize = (nuint)firstSubBlock * 120 * 256; assert(firstSubBlock == 0 || firstSubBlock == 1); @@ -730,8 +726,8 @@ public static unsafe partial class Methods ? (ebs.estBlockSize + targetCBlockSize / 2) / targetCBlockSize : 1; nuint n, - avgBlockBudget, - blockBudgetSupp = 0; + avgBlockBudget, + blockBudgetSupp = 0; avgBlockBudget = ebs.estBlockSize * 256 / nbSubBlocks; if (ebs.estBlockSize > srcSize) return 0; @@ -977,4 +973,4 @@ public static unsafe partial class Methods zc->tmpWkspSize ); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCwksp.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCwksp.cs index 4197aa63..236c94d4 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCwksp.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdCwksp.cs @@ -448,7 +448,7 @@ public static unsafe partial class Methods private static nuint ZSTD_cwksp_used(ZSTD_cwksp* ws) { return (nuint)((byte*)ws->tableEnd - (byte*)ws->workspace) - + (nuint)((byte*)ws->workspaceEnd - (byte*)ws->allocStart); + + (nuint)((byte*)ws->workspaceEnd - (byte*)ws->allocStart); } /** @@ -486,12 +486,7 @@ public static unsafe partial class Methods return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); } - ZSTD_cwksp_init( - ws, - workspace, - size, - ZSTD_cwksp_static_alloc_e.ZSTD_cwksp_dynamic_alloc - ); + ZSTD_cwksp_init(ws, workspace, size, ZSTD_cwksp_static_alloc_e.ZSTD_cwksp_dynamic_alloc); return 0; } @@ -533,8 +528,8 @@ public static unsafe partial class Methods return estimatedSpace - ZSTD_cwksp_slack_space_required() <= ZSTD_cwksp_used(ws) && ZSTD_cwksp_used(ws) <= estimatedSpace - ? 1 - : 0; + ? 1 + : 0; } /*-************************************* @@ -564,8 +559,8 @@ public static unsafe partial class Methods return ZSTD_cwksp_check_too_large(ws, additionalNeededSpace) != 0 && ws->workspaceOversizedDuration > 128 - ? 1 - : 0; + ? 1 + : 0; } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -583,4 +578,4 @@ public static unsafe partial class Methods ws->workspaceOversizedDuration = 0; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDdict.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDdict.cs index 0a840a2f..ce79c0f1 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDdict.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDdict.cs @@ -75,17 +75,13 @@ public static unsafe partial class Methods if (magic != 0xEC30A437) { if (dictContentType == ZSTD_dictContentType_e.ZSTD_dct_fullDict) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted)); return 0; } } ddict->dictID = MEM_readLE32((sbyte*)ddict->dictContent + 4); - if ( - ERR_isError(ZSTD_loadDEntropy(&ddict->entropy, ddict->dictContent, ddict->dictSize)) - ) + if (ERR_isError(ZSTD_loadDEntropy(&ddict->entropy, ddict->dictContent, ddict->dictSize))) { return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted)); } @@ -102,11 +98,7 @@ public static unsafe partial class Methods ZSTD_dictContentType_e dictContentType ) { - if ( - dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef - || dict == null - || dictSize == 0 - ) + if (dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef || dict == null || dictSize == 0) { ddict->dictBuffer = null; ddict->dictContent = dict; @@ -145,10 +137,7 @@ public static unsafe partial class Methods ZSTD_customMem customMem ) { - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; { ZSTD_DDict_s* ddict = (ZSTD_DDict_s*)ZSTD_customMalloc( @@ -277,13 +266,10 @@ public static unsafe partial class Methods /*! ZSTD_estimateDDictSize() : * Estimate amount of memory that will be needed to create a dictionary for decompression. * Note : dictionary created by reference using ZSTD_dlm_byRef are smaller */ - public static nuint ZSTD_estimateDDictSize( - nuint dictSize, - ZSTD_dictLoadMethod_e dictLoadMethod - ) + public static nuint ZSTD_estimateDDictSize(nuint dictSize, ZSTD_dictLoadMethod_e dictLoadMethod) { return (nuint)sizeof(ZSTD_DDict_s) - + (dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef ? 0 : dictSize); + + (dictLoadMethod == ZSTD_dictLoadMethod_e.ZSTD_dlm_byRef ? 0 : dictSize); } public static nuint ZSTD_sizeof_DDict(ZSTD_DDict_s* ddict) diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompress.cs index 8e629a5c..ab20f04c 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompress.cs @@ -91,10 +91,7 @@ public static unsafe partial class Methods /* Fetches a DDict with the given dictID * Returns the ZSTD_DDict* with the requested dictID. If it doesn't exist, then returns NULL. */ - private static ZSTD_DDict_s* ZSTD_DDictHashSet_getDDict( - ZSTD_DDictHashSet* hashSet, - uint dictID - ) + private static ZSTD_DDict_s* ZSTD_DDictHashSet_getDDict(ZSTD_DDictHashSet* hashSet, uint dictID) { nuint idx = ZSTD_DDictHashSet_getIndex(hashSet, dictID); nuint idxRangeMask = hashSet->ddictPtrTableSize - 1; @@ -145,10 +142,7 @@ public static unsafe partial class Methods /* Frees the table of ZSTD_DDict* within a hashset, then frees the hashset itself. * Note: The ZSTD_DDict* within the table are NOT freed. */ - private static void ZSTD_freeDDictHashSet( - ZSTD_DDictHashSet* hashSet, - ZSTD_customMem customMem - ) + private static void ZSTD_freeDDictHashSet(ZSTD_DDictHashSet* hashSet, ZSTD_customMem customMem) { if (hashSet != null && hashSet->ddictPtrTable != null) { @@ -198,9 +192,9 @@ public static unsafe partial class Methods if (dctx == null) return 0; return (nuint)sizeof(ZSTD_DCtx_s) - + ZSTD_sizeof_DDict(dctx->ddictLocal) - + dctx->inBuffSize - + dctx->outBuffSize; + + ZSTD_sizeof_DDict(dctx->ddictLocal) + + dctx->inBuffSize + + dctx->outBuffSize; } public static nuint ZSTD_estimateDCtxSize() @@ -212,8 +206,7 @@ public static unsafe partial class Methods { nuint startingInputLength = (nuint)(format == ZSTD_format_e.ZSTD_f_zstd1 ? 5 : 1); assert( - format == ZSTD_format_e.ZSTD_f_zstd1 - || format == ZSTD_format_e.ZSTD_f_zstd1_magicless + format == ZSTD_format_e.ZSTD_f_zstd1 || format == ZSTD_format_e.ZSTD_f_zstd1_magicless ); return startingInputLength; } @@ -264,10 +257,7 @@ public static unsafe partial class Methods private static ZSTD_DCtx_s* ZSTD_createDCtx_internal(ZSTD_customMem customMem) { - if ( - ((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) - != 0 - ) + if (((customMem.customAlloc == null ? 1 : 0) ^ (customMem.customFree == null ? 1 : 0)) != 0) return null; { ZSTD_DCtx_s* dctx = (ZSTD_DCtx_s*)ZSTD_customMalloc( @@ -419,10 +409,10 @@ public static unsafe partial class Methods uint singleSegment = (uint)(fhd >> 5 & 1); uint fcsId = (uint)(fhd >> 6); return minInputSize - + (nuint)(singleSegment == 0 ? 1 : 0) - + ZSTD_did_fieldSize[dictID] - + ZSTD_fcs_fieldSize[fcsId] - + (nuint)(singleSegment != 0 && fcsId == 0 ? 1 : 0); + + (nuint)(singleSegment == 0 ? 1 : 0) + + ZSTD_did_fieldSize[dictID] + + ZSTD_fcs_fieldSize[fcsId] + + (nuint)(singleSegment != 0 && fcsId == 0 ? 1 : 0); } } @@ -477,9 +467,7 @@ public static unsafe partial class Methods memcpy(hbuf, src, (uint)toCopy); if ((MEM_readLE32(hbuf) & 0xFFFFFFF0) != 0x184D2A50) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_prefix_unknown) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_prefix_unknown)); } } } @@ -643,9 +631,7 @@ public static unsafe partial class Methods sizeU32 = MEM_readLE32((byte*)src + 4); if (sizeU32 + 8 < sizeU32) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_unsupported)); } { @@ -778,12 +764,7 @@ public static unsafe partial class Methods * @return : 0 if success, or an error code, which can be tested using ZSTD_isError() */ private static nuint ZSTD_decodeFrameHeader(ZSTD_DCtx_s* dctx, void* src, nuint headerSize) { - nuint result = ZSTD_getFrameHeader_advanced( - &dctx->fParams, - src, - headerSize, - dctx->format - ); + nuint result = ZSTD_getFrameHeader_advanced(&dctx->fParams, src, headerSize, dctx->format); if (ERR_isError(result)) return result; if (result > 0) @@ -838,8 +819,7 @@ public static unsafe partial class Methods { frameSizeInfo.compressedSize = readSkippableFrameSize(src, srcSize); assert( - ERR_isError(frameSizeInfo.compressedSize) - || frameSizeInfo.compressedSize <= srcSize + ERR_isError(frameSizeInfo.compressedSize) || frameSizeInfo.compressedSize <= srcSize ); return frameSizeInfo; } @@ -997,8 +977,7 @@ public static unsafe partial class Methods margin += zfh.headerSize; margin += (nuint)(zfh.checksumFlag != 0 ? 4 : 0); margin += 3 * frameSizeInfo.nbBlocks; - maxBlockSize = - maxBlockSize > zfh.blockSizeMax ? maxBlockSize : zfh.blockSizeMax; + maxBlockSize = maxBlockSize > zfh.blockSizeMax ? maxBlockSize : zfh.blockSizeMax; } else { @@ -1024,12 +1003,7 @@ public static unsafe partial class Methods return blockSize; } - private static nuint ZSTD_copyRawBlock( - void* dst, - nuint dstCapacity, - void* src, - nuint srcSize - ) + private static nuint ZSTD_copyRawBlock(void* dst, nuint dstCapacity, void* src, nuint srcSize) { if (srcSize > dstCapacity) { @@ -1174,9 +1148,7 @@ public static unsafe partial class Methods break; case blockType_e.bt_reserved: default: - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } { @@ -1539,17 +1511,17 @@ public static unsafe partial class Methods assert(src != null); memcpy(dctx->headerBuffer + (dctx->headerSize - srcSize), src, (uint)srcSize); - { - nuint err_code = ZSTD_decodeFrameHeader( - dctx, - dctx->headerBuffer, - dctx->headerSize - ); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_decodeFrameHeader( + dctx, + dctx->headerBuffer, + dctx->headerSize + ); + if (ERR_isError(err_code)) + { + return err_code; + } } - } dctx->expected = ZSTD_blockHeaderSize; dctx->stage = ZSTD_dStage.ZSTDds_decodeBlockHeader; @@ -1562,9 +1534,7 @@ public static unsafe partial class Methods return cBlockSize; if (cBlockSize > dctx->fParams.blockSizeMax) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } dctx->expected = cBlockSize; @@ -1623,13 +1593,13 @@ public static unsafe partial class Methods assert(srcSize <= dctx->expected); rSize = ZSTD_copyRawBlock(dst, dstCapacity, src, srcSize); - { - nuint err_code = rSize; - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = rSize; + if (ERR_isError(err_code)) + { + return err_code; + } } - } assert(rSize == srcSize); dctx->expected -= rSize; @@ -1655,9 +1625,7 @@ public static unsafe partial class Methods if (rSize > dctx->fParams.blockSizeMax) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } dctx->decodedSize += rSize; @@ -1705,24 +1673,24 @@ public static unsafe partial class Methods case ZSTD_dStage.ZSTDds_checkChecksum: assert(srcSize == 4); - { - if (dctx->validateChecksum != 0) { - uint h32 = (uint)ZSTD_XXH64_digest(&dctx->xxhState); - uint check32 = MEM_readLE32(src); - if (check32 != h32) + if (dctx->validateChecksum != 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_checksum_wrong) - ); + uint h32 = (uint)ZSTD_XXH64_digest(&dctx->xxhState); + uint check32 = MEM_readLE32(src); + if (check32 != h32) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_checksum_wrong) + ); + } } - } - ZSTD_DCtx_trace_end(dctx, dctx->decodedSize, dctx->processedCSize, 1); - dctx->expected = 0; - dctx->stage = ZSTD_dStage.ZSTDds_getFrameHeaderSize; - return 0; - } + ZSTD_DCtx_trace_end(dctx, dctx->decodedSize, dctx->processedCSize, 1); + dctx->expected = 0; + dctx->stage = ZSTD_dStage.ZSTDds_getFrameHeaderSize; + return 0; + } case ZSTD_dStage.ZSTDds_decodeSkippableHeader: assert(src != null); @@ -1797,7 +1765,7 @@ public static unsafe partial class Methods { short* offcodeNCount = stackalloc short[32]; uint offcodeMaxValue = 31, - offcodeLog; + offcodeLog; nuint offcodeHeaderSize = FSE_readNCount( offcodeNCount, &offcodeMaxValue, @@ -1837,7 +1805,7 @@ public static unsafe partial class Methods { short* matchlengthNCount = stackalloc short[53]; uint matchlengthMaxValue = 52, - matchlengthLog; + matchlengthLog; nuint matchlengthHeaderSize = FSE_readNCount( matchlengthNCount, &matchlengthMaxValue, @@ -1877,7 +1845,7 @@ public static unsafe partial class Methods { short* litlengthNCount = stackalloc short[36]; uint litlengthMaxValue = 35, - litlengthLog; + litlengthLog; nuint litlengthHeaderSize = FSE_readNCount( litlengthNCount, &litlengthMaxValue, @@ -1928,9 +1896,7 @@ public static unsafe partial class Methods dictPtr += 4; if (rep == 0 || rep > dictContentSize) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dictionary_corrupted)); } entropy->rep[i] = rep; @@ -2463,11 +2429,7 @@ public static unsafe partial class Methods * @return : 0, or an error code (which can be tested using ZSTD_isError()). */ public static nuint ZSTD_DCtx_setFormat(ZSTD_DCtx_s* dctx, ZSTD_format_e format) { - return ZSTD_DCtx_setParameter( - dctx, - ZSTD_dParameter.ZSTD_d_experimentalParam1, - (int)format - ); + return ZSTD_DCtx_setParameter(dctx, ZSTD_dParameter.ZSTD_d_experimentalParam1, (int)format); } /*! ZSTD_dParam_getBounds() : @@ -2519,9 +2481,7 @@ public static unsafe partial class Methods break; } - bounds.error = unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported) - ); + bounds.error = unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_unsupported)); return bounds; } @@ -2545,11 +2505,7 @@ public static unsafe partial class Methods * and store it into int* value. * @return : 0, or an error code (which can be tested with ZSTD_isError()). */ - public static nuint ZSTD_DCtx_getParameter( - ZSTD_DCtx_s* dctx, - ZSTD_dParameter param, - int* value - ) + public static nuint ZSTD_DCtx_getParameter(ZSTD_DCtx_s* dctx, ZSTD_dParameter param, int* value) { switch (param) { @@ -2588,11 +2544,7 @@ public static unsafe partial class Methods * Setting a parameter is only possible during frame initialization (before starting decompression). * @return : 0, or an error code (which can be tested using ZSTD_isError()). */ - public static nuint ZSTD_DCtx_setParameter( - ZSTD_DCtx_s* dctx, - ZSTD_dParameter dParam, - int value - ) + public static nuint ZSTD_DCtx_setParameter(ZSTD_DCtx_s* dctx, ZSTD_dParameter dParam, int value) { if (dctx->streamStage != ZSTD_dStreamStage.zdss_init) { @@ -2605,85 +2557,74 @@ public static unsafe partial class Methods if (value == 0) value = 27; - { - if ( - ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_windowLogMax, value) - == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if (ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_windowLogMax, value) == 0) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } dctx->maxWindowSize = (nuint)1 << value; return 0; case ZSTD_dParameter.ZSTD_d_experimentalParam1: - { - if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam1, - value - ) == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if ( + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam1, value) + == 0 + ) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } dctx->format = (ZSTD_format_e)value; return 0; case ZSTD_dParameter.ZSTD_d_experimentalParam2: - { - if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam2, - value - ) == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if ( + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam2, value) + == 0 + ) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } dctx->outBufferMode = (ZSTD_bufferMode_e)value; return 0; case ZSTD_dParameter.ZSTD_d_experimentalParam3: - { - if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam3, - value - ) == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if ( + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam3, value) + == 0 + ) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } dctx->forceIgnoreChecksum = (ZSTD_forceIgnoreChecksum_e)value; return 0; case ZSTD_dParameter.ZSTD_d_experimentalParam4: - { - if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam4, - value - ) == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if ( + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam4, value) + == 0 + ) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } if (dctx->staticSize != 0) { @@ -2695,19 +2636,17 @@ public static unsafe partial class Methods dctx->refMultipleDDicts = (ZSTD_refMultipleDDicts_e)value; return 0; case ZSTD_dParameter.ZSTD_d_experimentalParam5: - { - if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam5, - value - ) == 0 - ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) - ); + if ( + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam5, value) + == 0 + ) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_parameter_outOfBound) + ); + } } - } dctx->disableHufAsm = value != 0 ? 1 : 0; return 0; @@ -2715,10 +2654,8 @@ public static unsafe partial class Methods if (value != 0) { if ( - ZSTD_dParam_withinBounds( - ZSTD_dParameter.ZSTD_d_experimentalParam6, - value - ) == 0 + ZSTD_dParam_withinBounds(ZSTD_dParameter.ZSTD_d_experimentalParam6, value) + == 0 ) { return unchecked( @@ -2881,11 +2818,7 @@ public static unsafe partial class Methods return 0; if (zds->streamStage == ZSTD_dStreamStage.zdss_init) return 0; - if ( - expect.dst == output->dst - && expect.pos == output->pos - && expect.size == output->size - ) + if (expect.dst == output->dst && expect.pos == output->pos && expect.size == output->size) return 0; return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstBuffer_wrong)); } @@ -3021,78 +2954,75 @@ public static unsafe partial class Methods zds->expectedOutBuffer = *output; goto case ZSTD_dStreamStage.zdss_loadHeader; case ZSTD_dStreamStage.zdss_loadHeader: - { - nuint hSize = ZSTD_getFrameHeader_advanced( - &zds->fParams, - zds->headerBuffer, - zds->lhSize, - zds->format - ); - if (zds->refMultipleDDicts != default && zds->ddictSet != null) { - ZSTD_DCtx_selectFrameDDict(zds); - } - - if (ERR_isError(hSize)) - { - return hSize; - } - - if (hSize != 0) - { - /* if hSize!=0, hSize > zds->lhSize */ - nuint toLoad = hSize - zds->lhSize; - nuint remainingInput = (nuint)(iend - ip); - assert(iend >= ip); - if (toLoad > remainingInput) + nuint hSize = ZSTD_getFrameHeader_advanced( + &zds->fParams, + zds->headerBuffer, + zds->lhSize, + zds->format + ); + if (zds->refMultipleDDicts != default && zds->ddictSet != null) { - if (remainingInput > 0) - { - memcpy( - zds->headerBuffer + zds->lhSize, - ip, - (uint)remainingInput - ); - zds->lhSize += remainingInput; - } - - input->pos = input->size; - { - /* check first few bytes */ - nuint err_code = ZSTD_getFrameHeader_advanced( - &zds->fParams, - zds->headerBuffer, - zds->lhSize, - zds->format - ); - if (ERR_isError(err_code)) - { - return err_code; - } - } - - return ( - (nuint)( - zds->format == ZSTD_format_e.ZSTD_f_zstd1 ? 6 : 2 - ) > hSize - ? (nuint)( - zds->format == ZSTD_format_e.ZSTD_f_zstd1 - ? 6 - : 2 - ) - : hSize - ) - - zds->lhSize - + ZSTD_blockHeaderSize; + ZSTD_DCtx_selectFrameDDict(zds); } - assert(ip != null); - memcpy(zds->headerBuffer + zds->lhSize, ip, (uint)toLoad); - zds->lhSize = hSize; - ip += toLoad; - break; + if (ERR_isError(hSize)) + { + return hSize; + } + + if (hSize != 0) + { + /* if hSize!=0, hSize > zds->lhSize */ + nuint toLoad = hSize - zds->lhSize; + nuint remainingInput = (nuint)(iend - ip); + assert(iend >= ip); + if (toLoad > remainingInput) + { + if (remainingInput > 0) + { + memcpy( + zds->headerBuffer + zds->lhSize, + ip, + (uint)remainingInput + ); + zds->lhSize += remainingInput; + } + + input->pos = input->size; + { + /* check first few bytes */ + nuint err_code = ZSTD_getFrameHeader_advanced( + &zds->fParams, + zds->headerBuffer, + zds->lhSize, + zds->format + ); + if (ERR_isError(err_code)) + { + return err_code; + } + } + + return ( + (nuint)(zds->format == ZSTD_format_e.ZSTD_f_zstd1 ? 6 : 2) + > hSize + ? (nuint)( + zds->format == ZSTD_format_e.ZSTD_f_zstd1 ? 6 : 2 + ) + : hSize + ) + - zds->lhSize + + ZSTD_blockHeaderSize; + } + + assert(ip != null); + memcpy(zds->headerBuffer + zds->lhSize, ip, (uint)toLoad); + zds->lhSize = hSize; + ip += toLoad; + break; + } } - } if ( zds->fParams.frameContentSize != unchecked(0UL - 1) @@ -3135,21 +3065,16 @@ public static unsafe partial class Methods && (nuint)(oend - op) < zds->fParams.frameContentSize ) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); } - { - nuint err_code = ZSTD_decompressBegin_usingDDict( - zds, - ZSTD_getDDict(zds) - ); - if (ERR_isError(err_code)) { - return err_code; + nuint err_code = ZSTD_decompressBegin_usingDDict(zds, ZSTD_getDDict(zds)); + if (ERR_isError(err_code)) + { + return err_code; + } } - } if ( zds->format == ZSTD_format_e.ZSTD_f_zstd1 @@ -3182,9 +3107,7 @@ public static unsafe partial class Methods if (zds->fParams.windowSize > zds->maxWindowSize) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_windowTooLarge - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_frameParameter_windowTooLarge) ); } @@ -3194,112 +3117,103 @@ public static unsafe partial class Methods ? zds->fParams.blockSizeMax : (uint)zds->maxBlockSizeParam; - { - /* frame checksum */ - nuint neededInBuffSize = - zds->fParams.blockSizeMax > 4 ? zds->fParams.blockSizeMax : 4; - nuint neededOutBuffSize = - zds->outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_buffered - ? ZSTD_decodingBufferSize_internal( - zds->fParams.windowSize, - zds->fParams.frameContentSize, - zds->fParams.blockSizeMax - ) - : 0; - ZSTD_DCtx_updateOversizedDuration( - zds, - neededInBuffSize, - neededOutBuffSize - ); { - int tooSmall = - zds->inBuffSize < neededInBuffSize - || zds->outBuffSize < neededOutBuffSize - ? 1 - : 0; - int tooLarge = ZSTD_DCtx_isOversizedTooLong(zds); - if (tooSmall != 0 || tooLarge != 0) - { - nuint bufferSize = neededInBuffSize + neededOutBuffSize; - if (zds->staticSize != 0) - { - assert(zds->staticSize >= (nuint)sizeof(ZSTD_DCtx_s)); - if ( - bufferSize - > zds->staticSize - (nuint)sizeof(ZSTD_DCtx_s) + /* frame checksum */ + nuint neededInBuffSize = + zds->fParams.blockSizeMax > 4 ? zds->fParams.blockSizeMax : 4; + nuint neededOutBuffSize = + zds->outBufferMode == ZSTD_bufferMode_e.ZSTD_bm_buffered + ? ZSTD_decodingBufferSize_internal( + zds->fParams.windowSize, + zds->fParams.frameContentSize, + zds->fParams.blockSizeMax ) - { - return unchecked( - (nuint)( - -(int) - ZSTD_ErrorCode.ZSTD_error_memory_allocation - ) - ); - } - } - else + : 0; + ZSTD_DCtx_updateOversizedDuration(zds, neededInBuffSize, neededOutBuffSize); + { + int tooSmall = + zds->inBuffSize < neededInBuffSize + || zds->outBuffSize < neededOutBuffSize + ? 1 + : 0; + int tooLarge = ZSTD_DCtx_isOversizedTooLong(zds); + if (tooSmall != 0 || tooLarge != 0) { - ZSTD_customFree(zds->inBuff, zds->customMem); - zds->inBuffSize = 0; - zds->outBuffSize = 0; - zds->inBuff = (sbyte*)ZSTD_customMalloc( - bufferSize, - zds->customMem - ); - if (zds->inBuff == null) + nuint bufferSize = neededInBuffSize + neededOutBuffSize; + if (zds->staticSize != 0) { - return unchecked( - (nuint)( - -(int) - ZSTD_ErrorCode.ZSTD_error_memory_allocation - ) - ); + assert(zds->staticSize >= (nuint)sizeof(ZSTD_DCtx_s)); + if (bufferSize > zds->staticSize - (nuint)sizeof(ZSTD_DCtx_s)) + { + return unchecked( + (nuint)( + -(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation + ) + ); + } + } + else + { + ZSTD_customFree(zds->inBuff, zds->customMem); + zds->inBuffSize = 0; + zds->outBuffSize = 0; + zds->inBuff = (sbyte*)ZSTD_customMalloc( + bufferSize, + zds->customMem + ); + if (zds->inBuff == null) + { + return unchecked( + (nuint)( + -(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation + ) + ); + } } - } - zds->inBuffSize = neededInBuffSize; - zds->outBuff = zds->inBuff + zds->inBuffSize; - zds->outBuffSize = neededOutBuffSize; + zds->inBuffSize = neededInBuffSize; + zds->outBuff = zds->inBuff + zds->inBuffSize; + zds->outBuffSize = neededOutBuffSize; + } } } - } zds->streamStage = ZSTD_dStreamStage.zdss_read; goto case ZSTD_dStreamStage.zdss_read; case ZSTD_dStreamStage.zdss_read: - { - nuint neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize( - zds, - (nuint)(iend - ip) - ); - if (neededInSize == 0) - { - zds->streamStage = ZSTD_dStreamStage.zdss_init; - someMoreWork = 0; - break; - } - - if ((nuint)(iend - ip) >= neededInSize) { + nuint neededInSize = ZSTD_nextSrcSizeToDecompressWithInputSize( + zds, + (nuint)(iend - ip) + ); + if (neededInSize == 0) { - nuint err_code = ZSTD_decompressContinueStream( - zds, - &op, - oend, - ip, - neededInSize - ); - if (ERR_isError(err_code)) - { - return err_code; - } + zds->streamStage = ZSTD_dStreamStage.zdss_init; + someMoreWork = 0; + break; } - assert(ip != null); - ip += neededInSize; - break; + if ((nuint)(iend - ip) >= neededInSize) + { + { + nuint err_code = ZSTD_decompressContinueStream( + zds, + &op, + oend, + ip, + neededInSize + ); + if (ERR_isError(err_code)) + { + return err_code; + } + } + + assert(ip != null); + ip += neededInSize; + break; + } } - } if (ip == iend) { @@ -3317,10 +3231,7 @@ public static unsafe partial class Methods nuint loadedSize; assert( neededInSize - == ZSTD_nextSrcSizeToDecompressWithInputSize( - zds, - (nuint)(iend - ip) - ) + == ZSTD_nextSrcSizeToDecompressWithInputSize(zds, (nuint)(iend - ip)) ); if (isSkipFrame != 0) { @@ -3374,30 +3285,30 @@ public static unsafe partial class Methods } case ZSTD_dStreamStage.zdss_flush: - { - nuint toFlushSize = zds->outEnd - zds->outStart; - nuint flushedSize = ZSTD_limitCopy( - op, - (nuint)(oend - op), - zds->outBuff + zds->outStart, - toFlushSize - ); - op = op != null ? op + flushedSize : op; - zds->outStart += flushedSize; - if (flushedSize == toFlushSize) { - zds->streamStage = ZSTD_dStreamStage.zdss_read; - if ( - zds->outBuffSize < zds->fParams.frameContentSize - && zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize - ) + nuint toFlushSize = zds->outEnd - zds->outStart; + nuint flushedSize = ZSTD_limitCopy( + op, + (nuint)(oend - op), + zds->outBuff + zds->outStart, + toFlushSize + ); + op = op != null ? op + flushedSize : op; + zds->outStart += flushedSize; + if (flushedSize == toFlushSize) { - zds->outStart = zds->outEnd = 0; - } + zds->streamStage = ZSTD_dStreamStage.zdss_read; + if ( + zds->outBuffSize < zds->fParams.frameContentSize + && zds->outStart + zds->fParams.blockSizeMax > zds->outBuffSize + ) + { + zds->outStart = zds->outEnd = 0; + } - break; + break; + } } - } someMoreWork = 0; break; @@ -3468,9 +3379,7 @@ public static unsafe partial class Methods nextSrcSizeHint += ZSTD_blockHeaderSize - * (nuint)( - ZSTD_nextInputType(zds) == ZSTD_nextInputType_e.ZSTDnit_block ? 1 : 0 - ); + * (nuint)(ZSTD_nextInputType(zds) == ZSTD_nextInputType_e.ZSTDnit_block ? 1 : 0); assert(zds->inPos <= nextSrcSizeHint); nextSrcSizeHint -= zds->inPos; return nextSrcSizeHint; @@ -3508,4 +3417,4 @@ public static unsafe partial class Methods return cErr; } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressBlock.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressBlock.cs index 380f9525..5fd65243 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressBlock.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressBlock.cs @@ -20,8 +20,7 @@ public static unsafe partial class Methods ***************************************************************/ private static nuint ZSTD_blockSizeMax(ZSTD_DCtx_s* dctx) { - nuint blockSizeMax = - dctx->isFrameDecompression != 0 ? dctx->fParams.blockSizeMax : 1 << 17; + nuint blockSizeMax = dctx->isFrameDecompression != 0 ? dctx->fParams.blockSizeMax : 1 << 17; assert(blockSizeMax <= 1 << 17); return blockSizeMax; } @@ -65,9 +64,7 @@ public static unsafe partial class Methods { nuint blockSizeMax = ZSTD_blockSizeMax(dctx); assert(litSize <= blockSizeMax); - assert( - dctx->isFrameDecompression != 0 || streaming == streaming_operation.not_streaming - ); + assert(dctx->isFrameDecompression != 0 || streaming == streaming_operation.not_streaming); assert(expectedWriteSize <= blockSizeMax); if ( streaming == streaming_operation.not_streaming @@ -148,206 +145,194 @@ public static unsafe partial class Methods ); } - { - nuint lhSize, - litSize, - litCSize; - uint singleStream = 0; - uint lhlCode = (uint)(istart[0] >> 2 & 3); - uint lhc = MEM_readLE32(istart); - nuint hufSuccess; - nuint expectedWriteSize = - blockSizeMax < dstCapacity ? blockSizeMax : dstCapacity; - int flags = - 0 - | ( - ZSTD_DCtx_get_bmi2(dctx) != 0 - ? (int)HUF_flags_e.HUF_flags_bmi2 - : 0 - ) - | ( - dctx->disableHufAsm != 0 - ? (int)HUF_flags_e.HUF_flags_disableAsm - : 0 - ); - switch (lhlCode) { - case 0: - case 1: - default: - singleStream = lhlCode == 0 ? 1U : 0U; - lhSize = 3; - litSize = lhc >> 4 & 0x3FF; - litCSize = lhc >> 14 & 0x3FF; - break; - case 2: - lhSize = 4; - litSize = lhc >> 4 & 0x3FFF; - litCSize = lhc >> 18; - break; - case 3: - lhSize = 5; - litSize = lhc >> 4 & 0x3FFFF; - litCSize = (lhc >> 22) + ((nuint)istart[4] << 10); - break; - } + nuint lhSize, + litSize, + litCSize; + uint singleStream = 0; + uint lhlCode = (uint)(istart[0] >> 2 & 3); + uint lhc = MEM_readLE32(istart); + nuint hufSuccess; + nuint expectedWriteSize = + blockSizeMax < dstCapacity ? blockSizeMax : dstCapacity; + int flags = + 0 + | (ZSTD_DCtx_get_bmi2(dctx) != 0 ? (int)HUF_flags_e.HUF_flags_bmi2 : 0) + | ( + dctx->disableHufAsm != 0 ? (int)HUF_flags_e.HUF_flags_disableAsm : 0 + ); + switch (lhlCode) + { + case 0: + case 1: + default: + singleStream = lhlCode == 0 ? 1U : 0U; + lhSize = 3; + litSize = lhc >> 4 & 0x3FF; + litCSize = lhc >> 14 & 0x3FF; + break; + case 2: + lhSize = 4; + litSize = lhc >> 4 & 0x3FFF; + litCSize = lhc >> 18; + break; + case 3: + lhSize = 5; + litSize = lhc >> 4 & 0x3FFFF; + litCSize = (lhc >> 22) + ((nuint)istart[4] << 10); + break; + } - if (litSize > 0 && dst == null) - { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); - } - - if (litSize > blockSizeMax) - { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); - } - - if (singleStream == 0) - if (litSize < 6) + if (litSize > 0 && dst == null) { return unchecked( - (nuint)( - -(int)ZSTD_ErrorCode.ZSTD_error_literals_headerWrong - ) + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) ); } - if (litCSize + lhSize > srcSize) - { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); - } - - if (expectedWriteSize < litSize) - { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); - } - - ZSTD_allocateLiteralsBuffer( - dctx, - dst, - dstCapacity, - litSize, - streaming, - expectedWriteSize, - 0 - ); - if (dctx->ddictIsCold != 0 && litSize > 768) - { - sbyte* _ptr = (sbyte*)dctx->HUFptr; - const nuint _size = sizeof(uint) * 4097; - nuint _pos; - for (_pos = 0; _pos < _size; _pos += 64) + if (litSize > blockSizeMax) { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) + ); + } + + if (singleStream == 0) + if (litSize < 6) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_literals_headerWrong) + ); + } + + if (litCSize + lhSize > srcSize) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) + ); + } + + if (expectedWriteSize < litSize) + { + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) + ); + } + + ZSTD_allocateLiteralsBuffer( + dctx, + dst, + dstCapacity, + litSize, + streaming, + expectedWriteSize, + 0 + ); + if (dctx->ddictIsCold != 0 && litSize > 768) + { + sbyte* _ptr = (sbyte*)dctx->HUFptr; + const nuint _size = sizeof(uint) * 4097; + nuint _pos; + for (_pos = 0; _pos < _size; _pos += 64) + { #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); + } #endif + } } - } - if (litEncType == SymbolEncodingType_e.set_repeat) - { - if (singleStream != 0) + if (litEncType == SymbolEncodingType_e.set_repeat) { - hufSuccess = HUF_decompress1X_usingDTable( - dctx->litBuffer, - litSize, - istart + lhSize, - litCSize, - dctx->HUFptr, - flags - ); + if (singleStream != 0) + { + hufSuccess = HUF_decompress1X_usingDTable( + dctx->litBuffer, + litSize, + istart + lhSize, + litCSize, + dctx->HUFptr, + flags + ); + } + else + { + assert(litSize >= 6); + hufSuccess = HUF_decompress4X_usingDTable( + dctx->litBuffer, + litSize, + istart + lhSize, + litCSize, + dctx->HUFptr, + flags + ); + } } else { - assert(litSize >= 6); - hufSuccess = HUF_decompress4X_usingDTable( - dctx->litBuffer, - litSize, - istart + lhSize, - litCSize, - dctx->HUFptr, - flags - ); + if (singleStream != 0) + { + hufSuccess = HUF_decompress1X1_DCtx_wksp( + dctx->entropy.hufTable, + dctx->litBuffer, + litSize, + istart + lhSize, + litCSize, + dctx->workspace, + sizeof(uint) * 640, + flags + ); + } + else + { + hufSuccess = HUF_decompress4X_hufOnly_wksp( + dctx->entropy.hufTable, + dctx->litBuffer, + litSize, + istart + lhSize, + litCSize, + dctx->workspace, + sizeof(uint) * 640, + flags + ); + } } - } - else - { - if (singleStream != 0) + + if (dctx->litBufferLocation == ZSTD_litLocation_e.ZSTD_split) { - hufSuccess = HUF_decompress1X1_DCtx_wksp( - dctx->entropy.hufTable, + assert(litSize > 1 << 16); + memcpy(dctx->litExtraBuffer, dctx->litBufferEnd - (1 << 16), 1 << 16); + memmove( + dctx->litBuffer + (1 << 16) - 32, dctx->litBuffer, - litSize, - istart + lhSize, - litCSize, - dctx->workspace, - sizeof(uint) * 640, - flags + litSize - (1 << 16) ); + dctx->litBuffer += (1 << 16) - 32; + dctx->litBufferEnd -= 32; + assert(dctx->litBufferEnd <= (byte*)dst + blockSizeMax); } - else + + if (ERR_isError(hufSuccess)) { - hufSuccess = HUF_decompress4X_hufOnly_wksp( - dctx->entropy.hufTable, - dctx->litBuffer, - litSize, - istart + lhSize, - litCSize, - dctx->workspace, - sizeof(uint) * 640, - flags + return unchecked( + (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) ); } - } - if (dctx->litBufferLocation == ZSTD_litLocation_e.ZSTD_split) - { - assert(litSize > 1 << 16); - memcpy( - dctx->litExtraBuffer, - dctx->litBufferEnd - (1 << 16), - 1 << 16 - ); - memmove( - dctx->litBuffer + (1 << 16) - 32, - dctx->litBuffer, - litSize - (1 << 16) - ); - dctx->litBuffer += (1 << 16) - 32; - dctx->litBufferEnd -= 32; - assert(dctx->litBufferEnd <= (byte*)dst + blockSizeMax); + dctx->litPtr = dctx->litBuffer; + dctx->litSize = litSize; + dctx->litEntropy = 1; + if (litEncType == SymbolEncodingType_e.set_compressed) + dctx->HUFptr = dctx->entropy.hufTable; + return litCSize + lhSize; } - if (ERR_isError(hufSuccess)) - { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); - } - - dctx->litPtr = dctx->litBuffer; - dctx->litSize = litSize; - dctx->litEntropy = 1; - if (litEncType == SymbolEncodingType_e.set_compressed) - dctx->HUFptr = dctx->entropy.hufTable; - return litCSize + lhSize; - } - case SymbolEncodingType_e.set_basic: { nuint litSize, - lhSize; + lhSize; uint lhlCode = (uint)(istart[0] >> 2 & 3); nuint expectedWriteSize = blockSizeMax < dstCapacity ? blockSizeMax : dstCapacity; @@ -378,9 +363,7 @@ public static unsafe partial class Methods if (litSize > 0 && dst == null) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); } if (litSize > blockSizeMax) @@ -392,9 +375,7 @@ public static unsafe partial class Methods if (expectedWriteSize < litSize) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); } ZSTD_allocateLiteralsBuffer( @@ -417,11 +398,7 @@ public static unsafe partial class Methods if (dctx->litBufferLocation == ZSTD_litLocation_e.ZSTD_split) { - memcpy( - dctx->litBuffer, - istart + lhSize, - (uint)(litSize - (1 << 16)) - ); + memcpy(dctx->litBuffer, istart + lhSize, (uint)(litSize - (1 << 16))); memcpy( dctx->litExtraBuffer, istart + lhSize + litSize - (1 << 16), @@ -449,7 +426,7 @@ public static unsafe partial class Methods { uint lhlCode = (uint)(istart[0] >> 2 & 3); nuint litSize, - lhSize; + lhSize; nuint expectedWriteSize = blockSizeMax < dstCapacity ? blockSizeMax : dstCapacity; switch (lhlCode) @@ -486,9 +463,7 @@ public static unsafe partial class Methods if (litSize > 0 && dst == null) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); } if (litSize > blockSizeMax) @@ -500,9 +475,7 @@ public static unsafe partial class Methods if (expectedWriteSize < litSize) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); } ZSTD_allocateLiteralsBuffer( @@ -530,9 +503,7 @@ public static unsafe partial class Methods } default: - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } } } @@ -635,94 +606,34 @@ public static unsafe partial class Methods new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 6, nbBits: 4, baseValue: 61), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 9, nbBits: 5, baseValue: 509), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 15, nbBits: 5, baseValue: 32765), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 21, - nbBits: 5, - baseValue: 2097149 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 21, nbBits: 5, baseValue: 2097149), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 3, nbBits: 5, baseValue: 5), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 7, nbBits: 4, baseValue: 125), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 12, nbBits: 5, baseValue: 4093), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 18, - nbBits: 5, - baseValue: 262141 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 23, - nbBits: 5, - baseValue: 8388605 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 18, nbBits: 5, baseValue: 262141), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 23, nbBits: 5, baseValue: 8388605), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 5, nbBits: 5, baseValue: 29), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 8, nbBits: 4, baseValue: 253), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 14, nbBits: 5, baseValue: 16381), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 20, - nbBits: 5, - baseValue: 1048573 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 20, nbBits: 5, baseValue: 1048573), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 2, nbBits: 5, baseValue: 1), new ZSTD_seqSymbol(nextState: 16, nbAdditionalBits: 7, nbBits: 4, baseValue: 125), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 11, nbBits: 5, baseValue: 2045), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 17, - nbBits: 5, - baseValue: 131069 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 22, - nbBits: 5, - baseValue: 4194301 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 17, nbBits: 5, baseValue: 131069), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 22, nbBits: 5, baseValue: 4194301), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 4, nbBits: 5, baseValue: 13), new ZSTD_seqSymbol(nextState: 16, nbAdditionalBits: 8, nbBits: 4, baseValue: 253), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 13, nbBits: 5, baseValue: 8189), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 19, - nbBits: 5, - baseValue: 524285 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 19, nbBits: 5, baseValue: 524285), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 1, nbBits: 5, baseValue: 1), new ZSTD_seqSymbol(nextState: 16, nbAdditionalBits: 6, nbBits: 4, baseValue: 61), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 10, nbBits: 5, baseValue: 1021), new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 16, nbBits: 5, baseValue: 65533), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 28, - nbBits: 5, - baseValue: 268435453 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 27, - nbBits: 5, - baseValue: 134217725 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 26, - nbBits: 5, - baseValue: 67108861 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 25, - nbBits: 5, - baseValue: 33554429 - ), - new ZSTD_seqSymbol( - nextState: 0, - nbAdditionalBits: 24, - nbBits: 5, - baseValue: 16777213 - ), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 28, nbBits: 5, baseValue: 268435453), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 27, nbBits: 5, baseValue: 134217725), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 26, nbBits: 5, baseValue: 67108861), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 25, nbBits: 5, baseValue: 33554429), + new ZSTD_seqSymbol(nextState: 0, nbAdditionalBits: 24, nbBits: 5, baseValue: 16777213), } ); private static readonly ZSTD_seqSymbol* ML_defaultDTable = GetArrayPointer( @@ -796,11 +707,7 @@ public static unsafe partial class Methods } ); - private static void ZSTD_buildSeqTable_rle( - ZSTD_seqSymbol* dt, - uint baseValue, - byte nbAddBits - ) + private static void ZSTD_buildSeqTable_rle(ZSTD_seqSymbol* dt, uint baseValue, byte nbAddBits) { void* ptr = dt; ZSTD_seqSymbol_header* DTableH = (ZSTD_seqSymbol_header*)ptr; @@ -916,7 +823,7 @@ public static unsafe partial class Methods uint tableMask = tableSize - 1; uint step = (tableSize >> 1) + (tableSize >> 3) + 3; uint s, - position = 0; + position = 0; for (s = 0; s < maxSV1; s++) { int i; @@ -1039,17 +946,15 @@ public static unsafe partial class Methods if (*(byte*)src > max) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } - { - uint symbol = *(byte*)src; - uint baseline = baseValue[symbol]; - byte nbBits = nbAdditionalBits[symbol]; - ZSTD_buildSeqTable_rle(DTableSpace, baseline, nbBits); - } + { + uint symbol = *(byte*)src; + uint baseline = baseValue[symbol]; + byte nbBits = nbAdditionalBits[symbol]; + ZSTD_buildSeqTable_rle(DTableSpace, baseline, nbBits); + } *DTablePtr = DTableSpace; return 1; @@ -1059,9 +964,7 @@ public static unsafe partial class Methods case SymbolEncodingType_e.set_repeat: if (flagRepeatTable == 0) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } if (ddictIsCold != 0 && nbSeq > 24) @@ -1075,10 +978,10 @@ public static unsafe partial class Methods for (_pos = 0; _pos < _size; _pos += 64) { #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); + } #endif } } @@ -1092,16 +995,12 @@ public static unsafe partial class Methods nuint headerSize = FSE_readNCount(norm, &max, &tableLog, src, srcSize); if (ERR_isError(headerSize)) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } if (tableLog > maxLog) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } ZSTD_buildFSETable( @@ -1215,9 +1114,7 @@ public static unsafe partial class Methods ); if (ERR_isError(llhSize)) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } ip += llhSize; @@ -1244,9 +1141,7 @@ public static unsafe partial class Methods ); if (ERR_isError(ofhSize)) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } ip += ofhSize; @@ -1273,9 +1168,7 @@ public static unsafe partial class Methods ); if (ERR_isError(mlhSize)) { - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_corruption_detected)); } ip += mlhSize; @@ -1286,12 +1179,12 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_dec32table => new uint[8] { 0, 1, 2, 1, 4, 4, 4, 4 }; - private static uint* dec32table => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_dec32table) - ); + private static ReadOnlySpan Span_dec32table => new uint[8] { 0, 1, 2, 1, 4, 4, 4, 4 }; + private static uint* dec32table => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_dec32table) + ); #else private static readonly uint* dec32table = GetArrayPointer( @@ -1299,12 +1192,12 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_dec64table => new int[8] { 8, 8, 8, 7, 8, 9, 10, 11 }; - private static int* dec64table => - (int*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_dec64table) - ); + private static ReadOnlySpan Span_dec64table => new int[8] { 8, 8, 8, 7, 8, 9, 10, 11 }; + private static int* dec64table => + (int*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_dec64table) + ); #else private static readonly int* dec64table = GetArrayPointer( @@ -1365,9 +1258,8 @@ public static unsafe partial class Methods nint diff = (nint)(op - ip); byte* oend = op + length; assert( - ovtype == ZSTD_overlap_e.ZSTD_no_overlap - && (diff <= -8 || diff >= 8 || op >= oend_w) - || ovtype == ZSTD_overlap_e.ZSTD_overlap_src_before_dst && diff >= 0 + ovtype == ZSTD_overlap_e.ZSTD_no_overlap && (diff <= -8 || diff >= 8 || op >= oend_w) + || ovtype == ZSTD_overlap_e.ZSTD_overlap_src_before_dst && diff >= 0 ); if (length < 8) { @@ -1672,12 +1564,7 @@ public static unsafe partial class Methods assert(sequence_matchLength >= 1); if (sequence_offset >= 16) { - ZSTD_wildcopy( - op, - match, - (nint)sequence_matchLength, - ZSTD_overlap_e.ZSTD_no_overlap - ); + ZSTD_wildcopy(op, match, (nint)sequence_matchLength, ZSTD_overlap_e.ZSTD_no_overlap); return sequenceLength; } @@ -1783,12 +1670,7 @@ public static unsafe partial class Methods assert(sequence.matchLength >= 1); if (sequence.offset >= 16) { - ZSTD_wildcopy( - op, - match, - (nint)sequence.matchLength, - ZSTD_overlap_e.ZSTD_no_overlap - ); + ZSTD_wildcopy(op, match, (nint)sequence.matchLength, ZSTD_overlap_e.ZSTD_no_overlap); return sequenceLength; } @@ -2189,10 +2071,8 @@ public static unsafe partial class Methods { uint i; for (i = 0; i < 3; i++) - System.Runtime.CompilerServices.Unsafe.Add( - ref seqState.prevOffset.e0, - (int)i - ) = dctx->entropy.rep[i]; + System.Runtime.CompilerServices.Unsafe.Add(ref seqState.prevOffset.e0, (int)i) = + dctx->entropy.rep[i]; } if (ERR_isError(BIT_initDStream(ref seqState.DStream, ip, (nuint)(iend - ip)))) @@ -2298,11 +2178,10 @@ public static unsafe partial class Methods ref seqState.prevOffset.e0, (int)ll0 ); - seqState.prevOffset.e1 = - System.Runtime.CompilerServices.Unsafe.Add( - ref seqState.prevOffset.e0, - ll0 == 0 ? 1 : 0 - ); + seqState.prevOffset.e1 = System.Runtime.CompilerServices.Unsafe.Add( + ref seqState.prevOffset.e0, + ll0 == 0 ? 1 : 0 + ); seqState.prevOffset.e0 = offset; } else @@ -2631,11 +2510,11 @@ public static unsafe partial class Methods (nint)sequence.offset ); #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch0(match); - System.Runtime.Intrinsics.X86.Sse.Prefetch0(match + 64); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch0(match); + System.Runtime.Intrinsics.X86.Sse.Prefetch0(match + 64); + } #endif } @@ -2788,12 +2667,7 @@ public static unsafe partial class Methods ); if (ERR_isError(oneSeqSize)) return oneSeqSize; - prefetchPos = ZSTD_prefetchMatch( - prefetchPos, - sequence, - prefixStart, - dictEnd - ); + prefetchPos = ZSTD_prefetchMatch(prefetchPos, sequence, prefixStart, dictEnd); sequences[seqNb & 8 - 1] = sequence; op += oneSeqSize; } @@ -3027,11 +2901,7 @@ public static unsafe partial class Methods */ private static ZSTD_OffsetInfo ZSTD_getOffsetInfo(ZSTD_seqSymbol* offTable, int nbSeq) { - ZSTD_OffsetInfo info = new ZSTD_OffsetInfo - { - longOffsetShare = 0, - maxNbAdditionalBits = 0, - }; + ZSTD_OffsetInfo info = new ZSTD_OffsetInfo { longOffsetShare = 0, maxNbAdditionalBits = 0 }; if (nbSeq != 0) { void* ptr = offTable; @@ -3290,11 +3160,7 @@ public static unsafe partial class Methods { void* ptr = dt; ZSTD_seqSymbol_header* DTableH = (ZSTD_seqSymbol_header*)ptr; - DStatePtr.state = BIT_readBits( - bitD.bitContainer, - ref bitD.bitsConsumed, - DTableH->tableLog - ); + DStatePtr.state = BIT_readBits(bitD.bitContainer, ref bitD.bitsConsumed, DTableH->tableLog); BIT_reloadDStream( ref bitD.bitContainer, ref bitD.bitsConsumed, @@ -3349,4 +3215,4 @@ public static unsafe partial class Methods op += 8; assert(op - ip >= 8); } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressInternal.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressInternal.cs index 96b38245..670f5846 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressInternal.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDecompressInternal.cs @@ -8,51 +8,51 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_LL_base => - new uint[36] - { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 18, - 20, - 22, - 24, - 28, - 32, - 40, - 48, - 64, - 0x80, - 0x100, - 0x200, - 0x400, - 0x800, - 0x1000, - 0x2000, - 0x4000, - 0x8000, - 0x10000, - }; - private static uint* LL_base => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_LL_base) - ); + private static ReadOnlySpan Span_LL_base => + new uint[36] + { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 18, + 20, + 22, + 24, + 28, + 32, + 40, + 48, + 64, + 0x80, + 0x100, + 0x200, + 0x400, + 0x800, + 0x1000, + 0x2000, + 0x4000, + 0x8000, + 0x10000, + }; + private static uint* LL_base => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_LL_base) + ); #else private static readonly uint* LL_base = GetArrayPointer( @@ -98,47 +98,47 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_OF_base => - new uint[32] - { - 0, - 1, - 1, - 5, - 0xD, - 0x1D, - 0x3D, - 0x7D, - 0xFD, - 0x1FD, - 0x3FD, - 0x7FD, - 0xFFD, - 0x1FFD, - 0x3FFD, - 0x7FFD, - 0xFFFD, - 0x1FFFD, - 0x3FFFD, - 0x7FFFD, - 0xFFFFD, - 0x1FFFFD, - 0x3FFFFD, - 0x7FFFFD, - 0xFFFFFD, - 0x1FFFFFD, - 0x3FFFFFD, - 0x7FFFFFD, - 0xFFFFFFD, - 0x1FFFFFFD, - 0x3FFFFFFD, - 0x7FFFFFFD, - }; - private static uint* OF_base => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_OF_base) - ); + private static ReadOnlySpan Span_OF_base => + new uint[32] + { + 0, + 1, + 1, + 5, + 0xD, + 0x1D, + 0x3D, + 0x7D, + 0xFD, + 0x1FD, + 0x3FD, + 0x7FD, + 0xFFD, + 0x1FFD, + 0x3FFD, + 0x7FFD, + 0xFFFD, + 0x1FFFD, + 0x3FFFD, + 0x7FFFD, + 0xFFFFD, + 0x1FFFFD, + 0x3FFFFD, + 0x7FFFFD, + 0xFFFFFD, + 0x1FFFFFD, + 0x3FFFFFD, + 0x7FFFFFD, + 0xFFFFFFD, + 0x1FFFFFFD, + 0x3FFFFFFD, + 0x7FFFFFFD, + }; + private static uint* OF_base => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_OF_base) + ); #else private static readonly uint* OF_base = GetArrayPointer( @@ -180,47 +180,47 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_OF_bits => - new byte[32] - { - 0, - 1, - 2, - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - }; - private static byte* OF_bits => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_OF_bits) - ); + private static ReadOnlySpan Span_OF_bits => + new byte[32] + { + 0, + 1, + 2, + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + }; + private static byte* OF_bits => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_OF_bits) + ); #else private static readonly byte* OF_bits = GetArrayPointer( @@ -262,68 +262,68 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_ML_base => - new uint[53] - { - 3, - 4, - 5, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - 17, - 18, - 19, - 20, - 21, - 22, - 23, - 24, - 25, - 26, - 27, - 28, - 29, - 30, - 31, - 32, - 33, - 34, - 35, - 37, - 39, - 41, - 43, - 47, - 51, - 59, - 67, - 83, - 99, - 0x83, - 0x103, - 0x203, - 0x403, - 0x803, - 0x1003, - 0x2003, - 0x4003, - 0x8003, - 0x10003, - }; - private static uint* ML_base => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_ML_base) - ); + private static ReadOnlySpan Span_ML_base => + new uint[53] + { + 3, + 4, + 5, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + 17, + 18, + 19, + 20, + 21, + 22, + 23, + 24, + 25, + 26, + 27, + 28, + 29, + 30, + 31, + 32, + 33, + 34, + 35, + 37, + 39, + 41, + 43, + 47, + 51, + 59, + 67, + 83, + 99, + 0x83, + 0x103, + 0x203, + 0x403, + 0x803, + 0x1003, + 0x2003, + 0x4003, + 0x8003, + 0x10003, + }; + private static uint* ML_base => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_ML_base) + ); #else private static readonly uint* ML_base = GetArrayPointer( diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDoubleFast.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDoubleFast.cs index bbc06b18..55d383ec 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDoubleFast.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdDoubleFast.cs @@ -99,13 +99,13 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_dummy => - new byte[10] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0xe2, 0xb4 }; - private static byte* dummy => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_dummy) - ); + private static ReadOnlySpan Span_dummy => + new byte[10] { 0x12, 0x34, 0x56, 0x78, 0x9a, 0xbc, 0xde, 0xf0, 0xe2, 0xb4 }; + private static byte* dummy => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_dummy) + ); #else private static readonly byte* dummy = GetArrayPointer( @@ -138,9 +138,9 @@ public static unsafe partial class Methods byte* iend = istart + srcSize; byte* ilimit = iend - 8; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; uint offsetSaved1 = 0, - offsetSaved2 = 0; + offsetSaved2 = 0; nuint mLength; uint offset; uint curr; @@ -252,11 +252,11 @@ public static unsafe partial class Methods if (ip1 >= nextStep) { #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch0(ip1 + 64); - System.Runtime.Intrinsics.X86.Sse.Prefetch0(ip1 + 128); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch0(ip1 + 64); + System.Runtime.Intrinsics.X86.Sse.Prefetch0(ip1 + 128); + } #endif step++; @@ -319,9 +319,7 @@ public static unsafe partial class Methods hashSmall[ZSTD_hashPtr(ip - 1, hBitsS, mls)] = (uint)(ip - 1 - @base); } - while ( - ip <= ilimit && offset_2 > 0 && MEM_read32(ip) == MEM_read32(ip - offset_2) - ) + while (ip <= ilimit && offset_2 > 0 && MEM_read32(ip) == MEM_read32(ip - offset_2)) { /* store sequence */ nuint rLength = ZSTD_count(ip + 4, ip + 4 - offset_2, iend) + 4; @@ -368,7 +366,7 @@ public static unsafe partial class Methods byte* iend = istart + srcSize; byte* ilimit = iend - 8; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; ZSTD_MatchState_t* dms = ms->dictMatchState; ZSTD_compressionParameters* dictCParams = &dms->cParams; uint* dictHashLong = dms->hashTable; @@ -393,10 +391,10 @@ public static unsafe partial class Methods for (_pos = 0; _pos < _size; _pos += 64) { #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); + } #endif } } @@ -408,10 +406,10 @@ public static unsafe partial class Methods for (_pos = 0; _pos < _size; _pos += 64) { #if NETCOREAPP3_0_OR_GREATER - if (System.Runtime.Intrinsics.X86.Sse.IsSupported) - { - System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); - } + if (System.Runtime.Intrinsics.X86.Sse.IsSupported) + { + System.Runtime.Intrinsics.X86.Sse.Prefetch1(_ptr + _pos); + } #endif } } @@ -450,13 +448,8 @@ public static unsafe partial class Methods { byte* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; mLength = - ZSTD_count_2segments( - ip + 1 + 4, - repMatch + 4, - iend, - repMatchEnd, - prefixLowest - ) + 4; + ZSTD_count_2segments(ip + 1 + 4, repMatch + 4, iend, repMatchEnd, prefixLowest) + + 4; ip++; assert(1 >= 1); assert(1 <= 3); @@ -486,13 +479,8 @@ public static unsafe partial class Methods if (dictMatchL > dictStart && MEM_read64(dictMatchL) == MEM_read64(ip)) { mLength = - ZSTD_count_2segments( - ip + 8, - dictMatchL + 8, - iend, - dictEnd, - prefixLowest - ) + 8; + ZSTD_count_2segments(ip + 8, dictMatchL + 8, iend, dictEnd, prefixLowest) + + 8; offset = curr - dictMatchIndexL - dictIndexDelta; while (ip > anchor && dictMatchL > dictStart && ip[-1] == dictMatchL[-1]) { @@ -538,10 +526,7 @@ public static unsafe partial class Methods ); byte* matchL3 = @base + matchIndexL3; hashLong[hl3] = curr + 1; - if ( - matchIndexL3 >= prefixLowestIndex - && MEM_read64(matchL3) == MEM_read64(ip + 1) - ) + if (matchIndexL3 >= prefixLowestIndex && MEM_read64(matchL3) == MEM_read64(ip + 1)) { mLength = ZSTD_count(ip + 9, matchL3 + 8, iend) + 8; ip++; @@ -561,10 +546,7 @@ public static unsafe partial class Methods uint dictMatchIndexL3 = dictMatchIndexAndTagL3 >> 8; byte* dictMatchL3 = dictBase + dictMatchIndexL3; assert(dictMatchL3 < dictEnd); - if ( - dictMatchL3 > dictStart - && MEM_read64(dictMatchL3) == MEM_read64(ip + 1) - ) + if (dictMatchL3 > dictStart && MEM_read64(dictMatchL3) == MEM_read64(ip + 1)) { mLength = ZSTD_count_2segments( @@ -576,9 +558,7 @@ public static unsafe partial class Methods ) + 8; ip++; offset = curr + 1 - dictMatchIndexL3 - dictIndexDelta; - while ( - ip > anchor && dictMatchL3 > dictStart && ip[-1] == dictMatchL3[-1] - ) + while (ip > anchor && dictMatchL3 > dictStart && ip[-1] == dictMatchL3[-1]) { ip--; dictMatchL3--; @@ -592,8 +572,7 @@ public static unsafe partial class Methods if (matchIndexS < prefixLowestIndex) { - mLength = - ZSTD_count_2segments(ip + 4, match + 4, iend, dictEnd, prefixLowest) + 4; + mLength = ZSTD_count_2segments(ip + 4, match + 4, iend, dictEnd, prefixLowest) + 4; offset = curr - matchIndexS; while (ip > anchor && match > dictStart && ip[-1] == match[-1]) { @@ -647,13 +626,8 @@ public static unsafe partial class Methods { byte* repEnd2 = repIndex2 < prefixLowestIndex ? dictEnd : iend; nuint repLength2 = - ZSTD_count_2segments( - ip + 4, - repMatch2 + 4, - iend, - repEnd2, - prefixLowest - ) + 4; + ZSTD_count_2segments(ip + 4, repMatch2 + 4, iend, repEnd2, prefixLowest) + + 4; /* swap offset_2 <=> offset_1 */ uint tmpOffset = offset_2; offset_2 = offset_1; @@ -894,7 +868,7 @@ public static unsafe partial class Methods byte* dictStart = dictBase + dictStartIndex; byte* dictEnd = dictBase + prefixStartIndex; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; if (prefixStartIndex == dictStartIndex) return ZSTD_compressBlock_doubleFast(ms, seqStore, rep, src, srcSize); while (ip < ilimit) @@ -924,13 +898,8 @@ public static unsafe partial class Methods { byte* repMatchEnd = repIndex < prefixStartIndex ? dictEnd : iend; mLength = - ZSTD_count_2segments( - ip + 1 + 4, - repMatch + 4, - iend, - repMatchEnd, - prefixStart - ) + 4; + ZSTD_count_2segments(ip + 1 + 4, repMatch + 4, iend, repMatchEnd, prefixStart) + + 4; ip++; assert(1 >= 1); assert(1 <= 3); @@ -941,8 +910,7 @@ public static unsafe partial class Methods if (matchLongIndex > dictStartIndex && MEM_read64(matchLong) == MEM_read64(ip)) { byte* matchEnd = matchLongIndex < prefixStartIndex ? dictEnd : iend; - byte* lowMatchPtr = - matchLongIndex < prefixStartIndex ? dictStart : prefixStart; + byte* lowMatchPtr = matchLongIndex < prefixStartIndex ? dictStart : prefixStart; uint offset; mLength = ZSTD_count_2segments(ip + 8, matchLong + 8, iend, matchEnd, prefixStart) @@ -975,22 +943,14 @@ public static unsafe partial class Methods byte* match3 = match3Base + matchIndex3; uint offset; hashLong[h3] = curr + 1; - if ( - matchIndex3 > dictStartIndex - && MEM_read64(match3) == MEM_read64(ip + 1) - ) + if (matchIndex3 > dictStartIndex && MEM_read64(match3) == MEM_read64(ip + 1)) { byte* matchEnd = matchIndex3 < prefixStartIndex ? dictEnd : iend; byte* lowMatchPtr = matchIndex3 < prefixStartIndex ? dictStart : prefixStart; mLength = - ZSTD_count_2segments( - ip + 9, - match3 + 8, - iend, - matchEnd, - prefixStart - ) + 8; + ZSTD_count_2segments(ip + 9, match3 + 8, iend, matchEnd, prefixStart) + + 8; ip++; offset = curr + 1 - matchIndex3; while (ip > anchor && match3 > lowMatchPtr && ip[-1] == match3[-1]) @@ -1003,8 +963,7 @@ public static unsafe partial class Methods else { byte* matchEnd = matchIndex < prefixStartIndex ? dictEnd : iend; - byte* lowMatchPtr = - matchIndex < prefixStartIndex ? dictStart : prefixStart; + byte* lowMatchPtr = matchIndex < prefixStartIndex ? dictStart : prefixStart; mLength = ZSTD_count_2segments(ip + 4, match + 4, iend, matchEnd, prefixStart) + 4; @@ -1064,13 +1023,8 @@ public static unsafe partial class Methods { byte* repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend; nuint repLength2 = - ZSTD_count_2segments( - ip + 4, - repMatch2 + 4, - iend, - repEnd2, - prefixStart - ) + 4; + ZSTD_count_2segments(ip + 4, repMatch2 + 4, iend, repEnd2, prefixStart) + + 4; /* swap offset_2 <=> offset_1 */ uint tmpOffset = offset_2; offset_2 = offset_1; @@ -1103,14 +1057,7 @@ public static unsafe partial class Methods nuint srcSize ) { - return ZSTD_compressBlock_doubleFast_extDict_generic( - ms, - seqStore, - rep, - src, - srcSize, - 4 - ); + return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 4); } private static nuint ZSTD_compressBlock_doubleFast_extDict_5( @@ -1121,14 +1068,7 @@ public static unsafe partial class Methods nuint srcSize ) { - return ZSTD_compressBlock_doubleFast_extDict_generic( - ms, - seqStore, - rep, - src, - srcSize, - 5 - ); + return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 5); } private static nuint ZSTD_compressBlock_doubleFast_extDict_6( @@ -1139,14 +1079,7 @@ public static unsafe partial class Methods nuint srcSize ) { - return ZSTD_compressBlock_doubleFast_extDict_generic( - ms, - seqStore, - rep, - src, - srcSize, - 6 - ); + return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 6); } private static nuint ZSTD_compressBlock_doubleFast_extDict_7( @@ -1157,14 +1090,7 @@ public static unsafe partial class Methods nuint srcSize ) { - return ZSTD_compressBlock_doubleFast_extDict_generic( - ms, - seqStore, - rep, - src, - srcSize, - 7 - ); + return ZSTD_compressBlock_doubleFast_extDict_generic(ms, seqStore, rep, src, srcSize, 7); } private static nuint ZSTD_compressBlock_doubleFast_extDict( diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdFast.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdFast.cs index bfe73ae0..518954b6 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdFast.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdFast.cs @@ -216,7 +216,7 @@ public static unsafe partial class Methods uint rep_offset1 = rep[0]; uint rep_offset2 = rep[1]; uint offsetSaved1 = 0, - offsetSaved2 = 0; + offsetSaved2 = 0; /* hash for ip0 */ nuint hash0; /* hash for ip1 */ @@ -564,7 +564,7 @@ public static unsafe partial class Methods byte* iend = istart + srcSize; byte* ilimit = iend - 8; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; ZSTD_MatchState_t* dms = ms->dictMatchState; ZSTD_compressionParameters* dictCParams = &dms->cParams; uint* dictHashTable = dms->hashTable; @@ -653,10 +653,7 @@ public static unsafe partial class Methods /* Found a possible dict match */ uint dictMatchIndex = dictMatchIndexAndTag >> 8; byte* dictMatch = dictBase + dictMatchIndex; - if ( - dictMatchIndex > dictStartIndex - && MEM_read32(dictMatch) == MEM_read32(ip0) - ) + if (dictMatchIndex > dictStartIndex && MEM_read32(dictMatch) == MEM_read32(ip0)) { if (matchIndex <= prefixStartIndex) { @@ -670,9 +667,7 @@ public static unsafe partial class Methods prefixStart ) + 4; while ( - ip0 > anchor - && dictMatch > dictStart - && ip0[-1] == dictMatch[-1] + ip0 > anchor && dictMatch > dictStart && ip0[-1] == dictMatch[-1] ) { ip0--; @@ -762,13 +757,8 @@ public static unsafe partial class Methods { byte* repEnd2 = repIndex2 < prefixStartIndex ? dictEnd : iend; nuint repLength2 = - ZSTD_count_2segments( - ip0 + 4, - repMatch2 + 4, - iend, - repEnd2, - prefixStart - ) + 4; + ZSTD_count_2segments(ip0 + 4, repMatch2 + 4, iend, repEnd2, prefixStart) + + 4; /* swap offset_2 <=> offset_1 */ uint tmpOffset = offset_2; offset_2 = offset_1; @@ -886,37 +876,13 @@ public static unsafe partial class Methods { default: case 4: - return ZSTD_compressBlock_fast_dictMatchState_4_0( - ms, - seqStore, - rep, - src, - srcSize - ); + return ZSTD_compressBlock_fast_dictMatchState_4_0(ms, seqStore, rep, src, srcSize); case 5: - return ZSTD_compressBlock_fast_dictMatchState_5_0( - ms, - seqStore, - rep, - src, - srcSize - ); + return ZSTD_compressBlock_fast_dictMatchState_5_0(ms, seqStore, rep, src, srcSize); case 6: - return ZSTD_compressBlock_fast_dictMatchState_6_0( - ms, - seqStore, - rep, - src, - srcSize - ); + return ZSTD_compressBlock_fast_dictMatchState_6_0(ms, seqStore, rep, src, srcSize); case 7: - return ZSTD_compressBlock_fast_dictMatchState_7_0( - ms, - seqStore, - rep, - src, - srcSize - ); + return ZSTD_compressBlock_fast_dictMatchState_7_0(ms, seqStore, rep, src, srcSize); } } @@ -950,9 +916,9 @@ public static unsafe partial class Methods byte* iend = istart + srcSize; byte* ilimit = iend - 8; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; uint offsetSaved1 = 0, - offsetSaved2 = 0; + offsetSaved2 = 0; byte* ip0 = istart; byte* ip1; byte* ip2; @@ -1043,8 +1009,7 @@ public static unsafe partial class Methods } { - uint mval = - idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; + uint mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; if (MEM_read32(ip0) == mval) { goto _offset; @@ -1061,8 +1026,7 @@ public static unsafe partial class Methods current0 = (uint)(ip0 - @base); hashTable[hash0] = current0; { - uint mval = - idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; + uint mval = idx >= dictStartIndex ? MEM_read32(idxBase + idx) : MEM_read32(ip0) ^ 1; if (MEM_read32(ip0) == mval) { goto _offset; @@ -1143,10 +1107,8 @@ public static unsafe partial class Methods byte* repMatch2 = repIndex2 < prefixStartIndex ? dictBase + repIndex2 : @base + repIndex2; if ( - ( - ZSTD_index_overlap_check(prefixStartIndex, repIndex2) - & (offset_2 > 0 ? 1 : 0) - ) != 0 + (ZSTD_index_overlap_check(prefixStartIndex, repIndex2) & (offset_2 > 0 ? 1 : 0)) + != 0 && MEM_read32(repMatch2) == MEM_read32(ip0) ) { @@ -1244,4 +1206,4 @@ public static unsafe partial class Methods return ZSTD_compressBlock_fast_extDict_7_0(ms, seqStore, rep, src, srcSize); } } -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdInternal.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdInternal.cs index 16f4c513..bea3765f 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdInternal.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdInternal.cs @@ -14,12 +14,12 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_repStartValue => new uint[3] { 1, 4, 8 }; - private static uint* repStartValue => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_repStartValue) - ); + private static ReadOnlySpan Span_repStartValue => new uint[3] { 1, 4, 8 }; + private static uint* repStartValue => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_repStartValue) + ); #else private static readonly uint* repStartValue = GetArrayPointer(new uint[3] { 1, 4, 8 }); @@ -32,51 +32,51 @@ public static unsafe partial class Methods ); private const uint ZSTD_blockHeaderSize = 3; #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_LL_bits => - new byte[36] - { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 2, - 2, - 3, - 3, - 4, - 6, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - }; - private static byte* LL_bits => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_LL_bits) - ); + private static ReadOnlySpan Span_LL_bits => + new byte[36] + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 2, + 3, + 3, + 4, + 6, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + }; + private static byte* LL_bits => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_LL_bits) + ); #else private static readonly byte* LL_bits = GetArrayPointer( @@ -122,51 +122,51 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_LL_defaultNorm => - new short[36] - { - 4, - 3, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 1, - 1, - 1, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 2, - 3, - 2, - 1, - 1, - 1, - 1, - 1, - -1, - -1, - -1, - -1, - }; - private static short* LL_defaultNorm => - (short*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_LL_defaultNorm) - ); + private static ReadOnlySpan Span_LL_defaultNorm => + new short[36] + { + 4, + 3, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 1, + 1, + 1, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 2, + 3, + 2, + 1, + 1, + 1, + 1, + 1, + -1, + -1, + -1, + -1, + }; + private static short* LL_defaultNorm => + (short*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_LL_defaultNorm) + ); #else private static readonly short* LL_defaultNorm = GetArrayPointer( @@ -213,68 +213,68 @@ public static unsafe partial class Methods #endif private const uint LL_defaultNormLog = 6; #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_ML_bits => - new byte[53] - { - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 1, - 1, - 1, - 1, - 2, - 2, - 3, - 3, - 4, - 4, - 5, - 7, - 8, - 9, - 10, - 11, - 12, - 13, - 14, - 15, - 16, - }; - private static byte* ML_bits => - (byte*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_ML_bits) - ); + private static ReadOnlySpan Span_ML_bits => + new byte[53] + { + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 0, + 1, + 1, + 1, + 1, + 2, + 2, + 3, + 3, + 4, + 4, + 5, + 7, + 8, + 9, + 10, + 11, + 12, + 13, + 14, + 15, + 16, + }; + private static byte* ML_bits => + (byte*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_ML_bits) + ); #else private static readonly byte* ML_bits = GetArrayPointer( @@ -337,68 +337,68 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_ML_defaultNorm => - new short[53] - { - 1, - 4, - 3, - 2, - 2, - 2, - 2, - 2, - 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - -1, - -1, - -1, - -1, - -1, - -1, - -1, - }; - private static short* ML_defaultNorm => - (short*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_ML_defaultNorm) - ); + private static ReadOnlySpan Span_ML_defaultNorm => + new short[53] + { + 1, + 4, + 3, + 2, + 2, + 2, + 2, + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + -1, + -1, + -1, + -1, + -1, + -1, + -1, + }; + private static short* ML_defaultNorm => + (short*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_ML_defaultNorm) + ); #else private static readonly short* ML_defaultNorm = GetArrayPointer( @@ -462,44 +462,44 @@ public static unsafe partial class Methods #endif private const uint ML_defaultNormLog = 6; #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_OF_defaultNorm => - new short[29] - { - 1, - 1, - 1, - 1, - 1, - 1, - 2, - 2, - 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - -1, - -1, - -1, - -1, - -1, - }; - private static short* OF_defaultNorm => - (short*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_OF_defaultNorm) - ); + private static ReadOnlySpan Span_OF_defaultNorm => + new short[29] + { + 1, + 1, + 1, + 1, + 1, + 1, + 2, + 2, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + -1, + -1, + -1, + -1, + -1, + }; + private static short* OF_defaultNorm => + (short*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_OF_defaultNorm) + ); #else private static readonly short* OF_defaultNorm = GetArrayPointer( @@ -555,24 +555,22 @@ public static unsafe partial class Methods private static void ZSTD_copy16(void* dst, void* src) { #if NET5_0_OR_GREATER - if (AdvSimd.IsSupported) - { - AdvSimd.Store((byte*)dst, AdvSimd.LoadVector128((byte*)src)); - } - else + if (AdvSimd.IsSupported) + { + AdvSimd.Store((byte*)dst, AdvSimd.LoadVector128((byte*)src)); + } + else #endif #if NETCOREAPP3_0_OR_GREATER - if (Sse2.IsSupported) - { - Sse2.Store((byte*)dst, Sse2.LoadVector128((byte*)src)); - } - else + if (Sse2.IsSupported) + { + Sse2.Store((byte*)dst, Sse2.LoadVector128((byte*)src)); + } + else #endif { var v1 = System.Runtime.CompilerServices.Unsafe.ReadUnaligned((ulong*)src); - var v2 = System.Runtime.CompilerServices.Unsafe.ReadUnaligned( - (ulong*)src + 1 - ); + var v2 = System.Runtime.CompilerServices.Unsafe.ReadUnaligned((ulong*)src + 1); System.Runtime.CompilerServices.Unsafe.WriteUnaligned((ulong*)dst, v1); System.Runtime.CompilerServices.Unsafe.WriteUnaligned((ulong*)dst + 1, v2); } diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLazy.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLazy.cs index e75c8476..2256ffbf 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLazy.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLazy.cs @@ -1,6 +1,7 @@ using System; using System.Numerics; using System.Runtime.CompilerServices; +using static SharpCompress.Compressors.ZStandard.UnsafeHelper; #if NETCOREAPP3_0_OR_GREATER using System.Runtime.Intrinsics; using System.Runtime.Intrinsics.X86; @@ -8,7 +9,6 @@ using System.Runtime.Intrinsics.X86; #if NET5_0_OR_GREATER using System.Runtime.Intrinsics.Arm; #endif -using static SharpCompress.Compressors.ZStandard.UnsafeHelper; namespace SharpCompress.Compressors.ZStandard.Unsafe; @@ -63,7 +63,7 @@ public static unsafe partial class Methods uint btLog = cParams->chainLog - 1; uint btMask = (uint)((1 << (int)btLog) - 1); nuint commonLengthSmaller = 0, - commonLengthLarger = 0; + commonLengthLarger = 0; byte* @base = ms->window.@base; byte* dictBase = ms->window.dictBase; uint dictLimit = ms->window.dictLimit; @@ -88,9 +88,7 @@ public static unsafe partial class Methods uint* nextPtr = bt + 2 * (matchIndex & btMask); /* guaranteed minimum nb of common bytes */ nuint matchLength = - commonLengthSmaller < commonLengthLarger - ? commonLengthSmaller - : commonLengthLarger; + commonLengthSmaller < commonLengthLarger ? commonLengthSmaller : commonLengthLarger; assert(matchIndex < curr); if ( dictMode != ZSTD_dictMode_e.ZSTD_extDict @@ -185,19 +183,16 @@ public static unsafe partial class Methods uint* dictBt = dms->chainTable; uint btLog = dmsCParams->chainLog - 1; uint btMask = (uint)((1 << (int)btLog) - 1); - uint btLow = - btMask >= dictHighLimit - dictLowLimit ? dictLowLimit : dictHighLimit - btMask; + uint btLow = btMask >= dictHighLimit - dictLowLimit ? dictLowLimit : dictHighLimit - btMask; nuint commonLengthSmaller = 0, - commonLengthLarger = 0; + commonLengthLarger = 0; assert(dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState); for (; nbCompares != 0 && dictMatchIndex > dictLowLimit; --nbCompares) { uint* nextPtr = dictBt + 2 * (dictMatchIndex & btMask); /* guaranteed minimum nb of common bytes */ nuint matchLength = - commonLengthSmaller < commonLengthLarger - ? commonLengthSmaller - : commonLengthLarger; + commonLengthSmaller < commonLengthLarger ? commonLengthSmaller : commonLengthLarger; byte* match = dictBase + dictMatchIndex; matchLength += ZSTD_count_2segments( ip + matchLength, @@ -317,7 +312,7 @@ public static unsafe partial class Methods { nuint commonLengthSmaller = 0, - commonLengthLarger = 0; + commonLengthLarger = 0; byte* dictBase = ms->window.dictBase; uint dictLimit = ms->window.dictLimit; byte* dictEnd = dictBase + dictLimit; @@ -618,10 +613,10 @@ public static unsafe partial class Methods for (ddsAttempt = 0; ddsAttempt < bucketSize - 1; ddsAttempt++) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(ddsBase + dms->hashTable[ddsIdx + ddsAttempt]); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(ddsBase + dms->hashTable[ddsIdx + ddsAttempt]); + } #endif } @@ -629,10 +624,10 @@ public static unsafe partial class Methods uint chainPackedPointer = dms->hashTable[ddsIdx + bucketSize - 1]; uint chainIndex = chainPackedPointer >> 8; #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(&dms->chainTable[chainIndex]); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(&dms->chainTable[chainIndex]); + } #endif } @@ -677,10 +672,10 @@ public static unsafe partial class Methods for (chainAttempt = 0; chainAttempt < chainLimit; chainAttempt++) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(ddsBase + dms->chainTable[chainIndex + chainAttempt]); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(ddsBase + dms->chainTable[chainIndex + chainAttempt]); + } #endif } @@ -695,8 +690,7 @@ public static unsafe partial class Methods if (MEM_read32(match) == MEM_read32(ip)) { currentMl = - ZSTD_count_2segments(ip + 4, match + 4, iLimit, ddsEnd, prefixStart) - + 4; + ZSTD_count_2segments(ip + 4, match + 4, iLimit, ddsEnd, prefixStart) + 4; } if (currentMl > ml) @@ -793,10 +787,10 @@ public static unsafe partial class Methods { uint* entry = &dms->hashTable[ddsIdx]; #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(entry); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(entry); + } #endif } @@ -823,8 +817,7 @@ public static unsafe partial class Methods assert(match + 4 <= dictEnd); if (MEM_read32(match) == MEM_read32(ip)) currentMl = - ZSTD_count_2segments(ip + 4, match + 4, iLimit, dictEnd, prefixStart) - + 4; + ZSTD_count_2segments(ip + 4, match + 4, iLimit, dictEnd, prefixStart) + 4; } if (currentMl > ml) @@ -876,8 +869,7 @@ public static unsafe partial class Methods assert(match + 4 <= dmsEnd); if (MEM_read32(match) == MEM_read32(ip)) currentMl = - ZSTD_count_2segments(ip + 4, match + 4, iLimit, dmsEnd, prefixStart) - + 4; + ZSTD_count_2segments(ip + 4, match + 4, iLimit, dmsEnd, prefixStart) + 4; if (currentMl > ml) { ml = currentMl; @@ -935,44 +927,39 @@ public static unsafe partial class Methods * Performs prefetching for the hashTable and tagTable at a given row. */ [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static void ZSTD_row_prefetch( - uint* hashTable, - byte* tagTable, - uint relRow, - uint rowLog - ) + private static void ZSTD_row_prefetch(uint* hashTable, byte* tagTable, uint relRow, uint rowLog) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(hashTable + relRow); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(hashTable + relRow); + } #endif if (rowLog >= 5) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(hashTable + relRow + 16); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(hashTable + relRow + 16); + } #endif } #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(tagTable + relRow); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(tagTable + relRow); + } #endif if (rowLog == 6) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(tagTable + relRow + 32); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(tagTable + relRow + 32); + } #endif } @@ -1080,13 +1067,7 @@ public static unsafe partial class Methods byte* tagRow = tagTable + relRow; uint pos = ZSTD_row_nextIndex(tagRow, rowMask); assert( - hash - == ZSTD_hashPtrSalted( - @base + updateStartIdx, - hashLog + 8, - mls, - ms->hashSalt - ) + hash == ZSTD_hashPtrSalted(@base + updateStartIdx, hashLog + 8, mls, ms->hashSalt) ); tagRow[pos] = (byte)(hash & (1U << 8) - 1); row[pos] = updateStartIdx; @@ -1155,71 +1136,71 @@ public static unsafe partial class Methods assert(rowEntries == 16 || rowEntries == 32 || rowEntries == 64); assert(rowEntries <= 64); #if NET5_0_OR_GREATER - if (AdvSimd.IsSupported && BitConverter.IsLittleEndian) - { - if (rowEntries == 16) - return 4; + if (AdvSimd.IsSupported && BitConverter.IsLittleEndian) + { + if (rowEntries == 16) + return 4; #if NET9_0_OR_GREATER - if (AdvSimd.Arm64.IsSupported) - { - if (rowEntries == 32) - return 2; - if (rowEntries == 64) - return 1; - } -#endif + if (AdvSimd.Arm64.IsSupported) + { + if (rowEntries == 32) + return 2; + if (rowEntries == 64) + return 1; } +#endif + } #endif return 1; } #if NETCOREAPP3_0_OR_GREATER - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static ulong ZSTD_row_getSSEMask(int nbChunks, byte* src, byte tag, uint head) + [MethodImpl(MethodImplOptions.AggressiveInlining)] + private static ulong ZSTD_row_getSSEMask(int nbChunks, byte* src, byte tag, uint head) + { + Vector128 comparisonMask = Vector128.Create(tag); + assert(nbChunks is 1 or 2 or 4); + if (nbChunks == 1) { - Vector128 comparisonMask = Vector128.Create(tag); - assert(nbChunks is 1 or 2 or 4); - if (nbChunks == 1) - { - Vector128 chunk0 = Sse2.LoadVector128(src); - Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); - int matches0 = Sse2.MoveMask(equalMask0); - return BitOperations.RotateRight((ushort)matches0, (int)head); - } - - if (nbChunks == 2) - { - Vector128 chunk0 = Sse2.LoadVector128(src); - Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); - int matches0 = Sse2.MoveMask(equalMask0); - Vector128 chunk1 = Sse2.LoadVector128(src + 16); - Vector128 equalMask1 = Sse2.CompareEqual(chunk1, comparisonMask); - int matches1 = Sse2.MoveMask(equalMask1); - return BitOperations.RotateRight((uint)matches1 << 16 | (uint)matches0, (int)head); - } - - { - Vector128 chunk0 = Sse2.LoadVector128(src); - Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); - int matches0 = Sse2.MoveMask(equalMask0); - Vector128 chunk1 = Sse2.LoadVector128(src + 16 * 1); - Vector128 equalMask1 = Sse2.CompareEqual(chunk1, comparisonMask); - int matches1 = Sse2.MoveMask(equalMask1); - Vector128 chunk2 = Sse2.LoadVector128(src + 16 * 2); - Vector128 equalMask2 = Sse2.CompareEqual(chunk2, comparisonMask); - int matches2 = Sse2.MoveMask(equalMask2); - Vector128 chunk3 = Sse2.LoadVector128(src + 16 * 3); - Vector128 equalMask3 = Sse2.CompareEqual(chunk3, comparisonMask); - int matches3 = Sse2.MoveMask(equalMask3); - return BitOperations.RotateRight( - (ulong)matches3 << 48 - | (ulong)matches2 << 32 - | (ulong)matches1 << 16 - | (uint)matches0, - (int)head - ); - } + Vector128 chunk0 = Sse2.LoadVector128(src); + Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); + int matches0 = Sse2.MoveMask(equalMask0); + return BitOperations.RotateRight((ushort)matches0, (int)head); } + + if (nbChunks == 2) + { + Vector128 chunk0 = Sse2.LoadVector128(src); + Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); + int matches0 = Sse2.MoveMask(equalMask0); + Vector128 chunk1 = Sse2.LoadVector128(src + 16); + Vector128 equalMask1 = Sse2.CompareEqual(chunk1, comparisonMask); + int matches1 = Sse2.MoveMask(equalMask1); + return BitOperations.RotateRight((uint)matches1 << 16 | (uint)matches0, (int)head); + } + + { + Vector128 chunk0 = Sse2.LoadVector128(src); + Vector128 equalMask0 = Sse2.CompareEqual(chunk0, comparisonMask); + int matches0 = Sse2.MoveMask(equalMask0); + Vector128 chunk1 = Sse2.LoadVector128(src + 16 * 1); + Vector128 equalMask1 = Sse2.CompareEqual(chunk1, comparisonMask); + int matches1 = Sse2.MoveMask(equalMask1); + Vector128 chunk2 = Sse2.LoadVector128(src + 16 * 2); + Vector128 equalMask2 = Sse2.CompareEqual(chunk2, comparisonMask); + int matches2 = Sse2.MoveMask(equalMask2); + Vector128 chunk3 = Sse2.LoadVector128(src + 16 * 3); + Vector128 equalMask3 = Sse2.CompareEqual(chunk3, comparisonMask); + int matches3 = Sse2.MoveMask(equalMask3); + return BitOperations.RotateRight( + (ulong)matches3 << 48 + | (ulong)matches2 << 32 + | (ulong)matches1 << 16 + | (uint)matches0, + (int)head + ); + } + } #endif /* Returns a ZSTD_VecMask (U64) that has the nth group (determined by @@ -1241,88 +1222,87 @@ public static unsafe partial class Methods assert(rowEntries <= 64); assert(ZSTD_row_matchMaskGroupWidth(rowEntries) * rowEntries <= sizeof(ulong) * 8); #if NETCOREAPP3_0_OR_GREATER - if (Sse2.IsSupported) - { - return ZSTD_row_getSSEMask((int)(rowEntries / 16), src, tag, headGrouped); - } + if (Sse2.IsSupported) + { + return ZSTD_row_getSSEMask((int)(rowEntries / 16), src, tag, headGrouped); + } #endif #if NET5_0_OR_GREATER - if (AdvSimd.IsSupported && BitConverter.IsLittleEndian) + if (AdvSimd.IsSupported && BitConverter.IsLittleEndian) + { + if (rowEntries == 16) { - if (rowEntries == 16) + /* vshrn_n_u16 shifts by 4 every u16 and narrows to 8 lower bits. + * After that groups of 4 bits represent the equalMask. We lower + * all bits except the highest in these groups by doing AND with + * 0x88 = 0b10001000. + */ + Vector128 chunk = AdvSimd.LoadVector128(src); + Vector128 equalMask = AdvSimd + .CompareEqual(chunk, AdvSimd.DuplicateToVector128(tag)) + .As(); + Vector64 res = AdvSimd.ShiftRightLogicalNarrowingLower(equalMask, 4); + ulong matches = res.As().GetElement(0); + return BitOperations.RotateRight(matches, (int)headGrouped) & 0x8888888888888888; + } + else if (rowEntries == 32) + { +#if NET9_0_OR_GREATER + if (AdvSimd.Arm64.IsSupported) { - /* vshrn_n_u16 shifts by 4 every u16 and narrows to 8 lower bits. - * After that groups of 4 bits represent the equalMask. We lower - * all bits except the highest in these groups by doing AND with - * 0x88 = 0b10001000. + /* Same idea as with rowEntries == 16 but doing AND with + * 0x55 = 0b01010101. */ - Vector128 chunk = AdvSimd.LoadVector128(src); - Vector128 equalMask = AdvSimd - .CompareEqual(chunk, AdvSimd.DuplicateToVector128(tag)) - .As(); - Vector64 res = AdvSimd.ShiftRightLogicalNarrowingLower(equalMask, 4); + (Vector128 chunk0, Vector128 chunk1) = + AdvSimd.Arm64.Load2xVector128AndUnzip((ushort*)src); + Vector128 dup = AdvSimd.DuplicateToVector128(tag); + Vector64 t0 = AdvSimd.ShiftRightLogicalNarrowingLower( + AdvSimd.CompareEqual(chunk0.As(), dup).As(), + 6 + ); + Vector64 t1 = AdvSimd.ShiftRightLogicalNarrowingLower( + AdvSimd.CompareEqual(chunk1.As(), dup).As(), + 6 + ); + Vector64 res = AdvSimd.ShiftLeftAndInsert(t0, t1, 4); ulong matches = res.As().GetElement(0); return BitOperations.RotateRight(matches, (int)headGrouped) - & 0x8888888888888888; + & 0x5555555555555555; } - else if (rowEntries == 32) - { -#if NET9_0_OR_GREATER - if (AdvSimd.Arm64.IsSupported) - { - /* Same idea as with rowEntries == 16 but doing AND with - * 0x55 = 0b01010101. - */ - (Vector128 chunk0, Vector128 chunk1) = - AdvSimd.Arm64.Load2xVector128AndUnzip((ushort*)src); - Vector128 dup = AdvSimd.DuplicateToVector128(tag); - Vector64 t0 = AdvSimd.ShiftRightLogicalNarrowingLower( - AdvSimd.CompareEqual(chunk0.As(), dup).As(), - 6 - ); - Vector64 t1 = AdvSimd.ShiftRightLogicalNarrowingLower( - AdvSimd.CompareEqual(chunk1.As(), dup).As(), - 6 - ); - Vector64 res = AdvSimd.ShiftLeftAndInsert(t0, t1, 4); - ulong matches = res.As().GetElement(0); - return BitOperations.RotateRight(matches, (int)headGrouped) - & 0x5555555555555555; - } #endif - } - else - { /* rowEntries == 64 */ -#if NET9_0_OR_GREATER - if (AdvSimd.Arm64.IsSupported) - { - ( - Vector128 chunk0, - Vector128 chunk1, - Vector128 chunk2, - Vector128 chunk3 - ) = AdvSimd.Arm64.Load4xVector128AndUnzip(src); - Vector128 dup = AdvSimd.DuplicateToVector128(tag); - Vector128 cmp0 = AdvSimd.CompareEqual(chunk0, dup); - Vector128 cmp1 = AdvSimd.CompareEqual(chunk1, dup); - Vector128 cmp2 = AdvSimd.CompareEqual(chunk2, dup); - Vector128 cmp3 = AdvSimd.CompareEqual(chunk3, dup); - - Vector128 t0 = AdvSimd.ShiftRightAndInsert(cmp1, cmp0, 1); - Vector128 t1 = AdvSimd.ShiftRightAndInsert(cmp3, cmp2, 1); - Vector128 t2 = AdvSimd.ShiftRightAndInsert(t1, t0, 2); - Vector128 t3 = AdvSimd.ShiftRightAndInsert(t2, t2, 4); - Vector64 t4 = AdvSimd.ShiftRightLogicalNarrowingLower( - t3.As(), - 4 - ); - ulong matches = t4.As().GetElement(0); - return BitOperations.RotateRight(matches, (int)headGrouped); - } -#endif - } } + else + { /* rowEntries == 64 */ +#if NET9_0_OR_GREATER + if (AdvSimd.Arm64.IsSupported) + { + ( + Vector128 chunk0, + Vector128 chunk1, + Vector128 chunk2, + Vector128 chunk3 + ) = AdvSimd.Arm64.Load4xVector128AndUnzip(src); + Vector128 dup = AdvSimd.DuplicateToVector128(tag); + Vector128 cmp0 = AdvSimd.CompareEqual(chunk0, dup); + Vector128 cmp1 = AdvSimd.CompareEqual(chunk1, dup); + Vector128 cmp2 = AdvSimd.CompareEqual(chunk2, dup); + Vector128 cmp3 = AdvSimd.CompareEqual(chunk3, dup); + + Vector128 t0 = AdvSimd.ShiftRightAndInsert(cmp1, cmp0, 1); + Vector128 t1 = AdvSimd.ShiftRightAndInsert(cmp3, cmp2, 1); + Vector128 t2 = AdvSimd.ShiftRightAndInsert(t1, t0, 2); + Vector128 t3 = AdvSimd.ShiftRightAndInsert(t2, t2, 4); + Vector64 t4 = AdvSimd.ShiftRightLogicalNarrowingLower( + t3.As(), + 4 + ); + ulong matches = t4.As().GetElement(0); + return BitOperations.RotateRight(matches, (int)headGrouped); + } +#endif + } + } #endif { @@ -1446,10 +1426,10 @@ public static unsafe partial class Methods { ddsIdx = ZSTD_hashPtr(ip, ddsHashLog, mls) << 2; #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(&dms->hashTable[ddsIdx]); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(&dms->hashTable[ddsIdx]); + } #endif } @@ -1504,8 +1484,7 @@ public static unsafe partial class Methods ulong matches = ZSTD_row_getMatchMask(tagRow, (byte)tag, headGrouped, rowEntries); for (; matches > 0 && nbAttempts > 0; matches &= matches - 1) { - uint matchPos = - (headGrouped + ZSTD_VecMask_next(matches)) / groupWidth & rowMask; + uint matchPos = (headGrouped + ZSTD_VecMask_next(matches)) / groupWidth & rowMask; uint matchIndex = row[matchPos]; if (matchPos == 0) continue; @@ -1515,19 +1494,19 @@ public static unsafe partial class Methods if (dictMode != ZSTD_dictMode_e.ZSTD_extDict || matchIndex >= dictLimit) { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(@base + matchIndex); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(@base + matchIndex); + } #endif } else { #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(dictBase + matchIndex); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(dictBase + matchIndex); + } #endif } @@ -1560,13 +1539,8 @@ public static unsafe partial class Methods assert(match + 4 <= dictEnd); if (MEM_read32(match) == MEM_read32(ip)) currentMl = - ZSTD_count_2segments( - ip + 4, - match + 4, - iLimit, - dictEnd, - prefixStart - ) + 4; + ZSTD_count_2segments(ip + 4, match + 4, iLimit, dictEnd, prefixStart) + + 4; } if (currentMl > ml) @@ -1625,10 +1599,10 @@ public static unsafe partial class Methods if (matchIndex < dmsLowestIndex) break; #if NETCOREAPP3_0_OR_GREATER - if (Sse.IsSupported) - { - Sse.Prefetch0(dmsBase + matchIndex); - } + if (Sse.IsSupported) + { + Sse.Prefetch0(dmsBase + matchIndex); + } #endif matchBuffer[numMatches++] = matchIndex; @@ -1646,13 +1620,8 @@ public static unsafe partial class Methods assert(match + 4 <= dmsEnd); if (MEM_read32(match) == MEM_read32(ip)) currentMl = - ZSTD_count_2segments( - ip + 4, - match + 4, - iLimit, - dmsEnd, - prefixStart - ) + 4; + ZSTD_count_2segments(ip + 4, match + 4, iLimit, dmsEnd, prefixStart) + + 4; } if (currentMl > ml) @@ -1693,15 +1662,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_noDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_noDict, 4); } private static nuint ZSTD_RowFindBestMatch_noDict_4_5( @@ -1725,15 +1686,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_noDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_noDict, 5); } private static nuint ZSTD_RowFindBestMatch_noDict_4_6( @@ -1757,15 +1710,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_noDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_noDict, 6); } private static nuint ZSTD_RowFindBestMatch_noDict_5_4( @@ -1789,15 +1734,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_noDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_noDict, 4); } private static nuint ZSTD_RowFindBestMatch_noDict_5_5( @@ -1821,15 +1758,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_noDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_noDict, 5); } private static nuint ZSTD_RowFindBestMatch_noDict_5_6( @@ -1853,15 +1782,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_noDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_noDict, 6); } private static nuint ZSTD_RowFindBestMatch_noDict_6_4( @@ -1885,15 +1806,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_noDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_noDict, 4); } private static nuint ZSTD_RowFindBestMatch_noDict_6_5( @@ -1917,15 +1830,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_noDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_noDict, 5); } private static nuint ZSTD_RowFindBestMatch_noDict_6_6( @@ -1949,15 +1854,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_noDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_noDict, 6); } private static nuint ZSTD_RowFindBestMatch_extDict_4_4( @@ -1981,15 +1878,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_extDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_extDict, 4); } private static nuint ZSTD_RowFindBestMatch_extDict_4_5( @@ -2013,15 +1902,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_extDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_extDict, 5); } private static nuint ZSTD_RowFindBestMatch_extDict_4_6( @@ -2045,15 +1926,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 4, - ZSTD_dictMode_e.ZSTD_extDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 4, ZSTD_dictMode_e.ZSTD_extDict, 6); } private static nuint ZSTD_RowFindBestMatch_extDict_5_4( @@ -2077,15 +1950,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_extDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_extDict, 4); } private static nuint ZSTD_RowFindBestMatch_extDict_5_5( @@ -2109,15 +1974,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_extDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_extDict, 5); } private static nuint ZSTD_RowFindBestMatch_extDict_5_6( @@ -2141,15 +1998,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 5, - ZSTD_dictMode_e.ZSTD_extDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 5, ZSTD_dictMode_e.ZSTD_extDict, 6); } private static nuint ZSTD_RowFindBestMatch_extDict_6_4( @@ -2173,15 +2022,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 4 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_extDict, - 4 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_extDict, 4); } private static nuint ZSTD_RowFindBestMatch_extDict_6_5( @@ -2205,15 +2046,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 5 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_extDict, - 5 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_extDict, 5); } private static nuint ZSTD_RowFindBestMatch_extDict_6_6( @@ -2237,15 +2070,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog ) == 6 ); - return ZSTD_RowFindBestMatch( - ms, - ip, - iLimit, - offsetPtr, - 6, - ZSTD_dictMode_e.ZSTD_extDict, - 6 - ); + return ZSTD_RowFindBestMatch(ms, ip, iLimit, offsetPtr, 6, ZSTD_dictMode_e.ZSTD_extDict, 6); } private static nuint ZSTD_RowFindBestMatch_dictMatchState_4_4( @@ -2890,14 +2715,7 @@ public static unsafe partial class Methods : ms->cParams.minMatch ) == 4 ); - return ZSTD_BtFindBestMatch( - ms, - ip, - iLimit, - offBasePtr, - 4, - ZSTD_dictMode_e.ZSTD_extDict - ); + return ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 4, ZSTD_dictMode_e.ZSTD_extDict); } private static nuint ZSTD_BtFindBestMatch_extDict_5( @@ -2914,14 +2732,7 @@ public static unsafe partial class Methods : ms->cParams.minMatch ) == 5 ); - return ZSTD_BtFindBestMatch( - ms, - ip, - iLimit, - offBasePtr, - 5, - ZSTD_dictMode_e.ZSTD_extDict - ); + return ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 5, ZSTD_dictMode_e.ZSTD_extDict); } private static nuint ZSTD_BtFindBestMatch_extDict_6( @@ -2938,14 +2749,7 @@ public static unsafe partial class Methods : ms->cParams.minMatch ) == 6 ); - return ZSTD_BtFindBestMatch( - ms, - ip, - iLimit, - offBasePtr, - 6, - ZSTD_dictMode_e.ZSTD_extDict - ); + return ZSTD_BtFindBestMatch(ms, ip, iLimit, offBasePtr, 6, ZSTD_dictMode_e.ZSTD_extDict); } private static nuint ZSTD_BtFindBestMatch_dictMatchState_4( @@ -3477,57 +3281,27 @@ public static unsafe partial class Methods if (mls == 4) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dictMatchState_4_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_4_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dictMatchState_4_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_4_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dictMatchState_4_6(ms, ip, iend, offsetPtr); } if (mls == 5) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dictMatchState_5_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_5_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dictMatchState_5_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_5_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dictMatchState_5_6(ms, ip, iend, offsetPtr); } if (mls == 6) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dictMatchState_6_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_6_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dictMatchState_6_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dictMatchState_6_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dictMatchState_6_6(ms, ip, iend, offsetPtr); } } @@ -3554,57 +3328,27 @@ public static unsafe partial class Methods if (mls == 4) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dedicatedDictSearch_4_6(ms, ip, iend, offsetPtr); } if (mls == 5) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dedicatedDictSearch_5_6(ms, ip, iend, offsetPtr); } if (mls == 6) { if (rowLog == 4) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_4( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_4(ms, ip, iend, offsetPtr); if (rowLog == 5) - return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_5( - ms, - ip, - iend, - offsetPtr - ); + return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_5(ms, ip, iend, offsetPtr); return ZSTD_RowFindBestMatch_dedicatedDictSearch_6_6(ms, ip, iend, offsetPtr); } } @@ -3658,9 +3402,9 @@ public static unsafe partial class Methods : ms->cParams.searchLog <= 6 ? ms->cParams.searchLog : 6; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; uint offsetSaved1 = 0, - offsetSaved2 = 0; + offsetSaved2 = 0; int isDMS = dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? 1 : 0; int isDDS = dictMode == ZSTD_dictMode_e.ZSTD_dedicatedDictSearch ? 1 : 0; int isDxS = isDMS != 0 || isDDS != 0 ? 1 : 0; @@ -3827,9 +3571,7 @@ public static unsafe partial class Methods prefixLowest ) + 4; int gain2 = (int)(mlRep * 3); - int gain1 = (int)( - matchLength * 3 - ZSTD_highbit32((uint)offBase) + 1 - ); + int gain1 = (int)(matchLength * 3 - ZSTD_highbit32((uint)offBase) + 1); if (mlRep >= 4 && gain2 > gain1) { matchLength = mlRep; @@ -3877,9 +3619,7 @@ public static unsafe partial class Methods { nuint mlRep = ZSTD_count(ip + 4, ip + 4 - offset_1, iend) + 4; int gain2 = (int)(mlRep * 4); - int gain1 = (int)( - matchLength * 4 - ZSTD_highbit32((uint)offBase) + 1 - ); + int gain1 = (int)(matchLength * 4 - ZSTD_highbit32((uint)offBase) + 1); if (mlRep >= 4 && gain2 > gain1) { matchLength = mlRep; @@ -3902,8 +3642,7 @@ public static unsafe partial class Methods && MEM_read32(repMatch) == MEM_read32(ip) ) { - byte* repMatchEnd = - repIndex < prefixLowestIndex ? dictEnd : iend; + byte* repMatchEnd = repIndex < prefixLowestIndex ? dictEnd : iend; nuint mlRep = ZSTD_count_2segments( ip + 4, @@ -3941,9 +3680,7 @@ public static unsafe partial class Methods ); /* raw approx */ int gain2 = (int)(ml2 * 4 - ZSTD_highbit32((uint)ofbCandidate)); - int gain1 = (int)( - matchLength * 4 - ZSTD_highbit32((uint)offBase) + 7 - ); + int gain1 = (int)(matchLength * 4 - ZSTD_highbit32((uint)offBase) + 7); if (ml2 >= 4 && gain2 > gain1) { matchLength = ml2; @@ -4030,13 +3767,8 @@ public static unsafe partial class Methods { byte* repEnd2 = repIndex < prefixLowestIndex ? dictEnd : iend; matchLength = - ZSTD_count_2segments( - ip + 4, - repMatch + 4, - iend, - repEnd2, - prefixLowest - ) + 4; + ZSTD_count_2segments(ip + 4, repMatch + 4, iend, repEnd2, prefixLowest) + + 4; offBase = offset_2; offset_2 = offset_1; offset_1 = (uint)offBase; @@ -4054,9 +3786,7 @@ public static unsafe partial class Methods if (dictMode == ZSTD_dictMode_e.ZSTD_noDict) { - while ( - ip <= ilimit && offset_2 > 0 && MEM_read32(ip) == MEM_read32(ip - offset_2) - ) + while (ip <= ilimit && offset_2 > 0 && MEM_read32(ip) == MEM_read32(ip - offset_2)) { matchLength = ZSTD_count(ip + 4, ip + 4 - offset_2, iend) + 4; offBase = offset_2; @@ -4510,7 +4240,7 @@ public static unsafe partial class Methods : ms->cParams.searchLog <= 6 ? ms->cParams.searchLog : 6; uint offset_1 = rep[0], - offset_2 = rep[1]; + offset_2 = rep[1]; ms->lazySkipping = 0; ip += ip == prefixStart ? 1 : 0; if (searchMethod == searchMethod_e.search_rowHash) @@ -4707,9 +4437,7 @@ public static unsafe partial class Methods ); /* raw approx */ int gain2 = (int)(ml2 * 4 - ZSTD_highbit32((uint)ofbCandidate)); - int gain1 = (int)( - matchLength * 4 - ZSTD_highbit32((uint)offBase) + 7 - ); + int gain1 = (int)(matchLength * 4 - ZSTD_highbit32((uint)offBase) + 7); if (ml2 >= 4 && gain2 > gain1) { matchLength = ml2; @@ -4727,8 +4455,7 @@ public static unsafe partial class Methods { assert(offBase > 3); uint matchIndex = (uint)((nuint)(start - @base) - (offBase - 3)); - byte* match = - matchIndex < dictLimit ? dictBase + matchIndex : @base + matchIndex; + byte* match = matchIndex < dictLimit ? dictBase + matchIndex : @base + matchIndex; byte* mStart = matchIndex < dictLimit ? dictStart : prefixStart; while (start > anchor && match > mStart && start[-1] == match[-1]) { @@ -4777,13 +4504,8 @@ public static unsafe partial class Methods /* repcode detected we should take it */ byte* repEnd = repIndex < dictLimit ? dictEnd : iend; matchLength = - ZSTD_count_2segments( - ip + 4, - repMatch + 4, - iend, - repEnd, - prefixStart - ) + 4; + ZSTD_count_2segments(ip + 4, repMatch + 4, iend, repEnd, prefixStart) + + 4; offBase = offset_2; offset_2 = offset_1; offset_1 = (uint)offBase; diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdm.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdm.cs index 6b8c3471..eb634979 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdm.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdm.cs @@ -86,7 +86,7 @@ public static unsafe partial class Methods { nuint n; ulong hash, - mask; + mask; hash = state->rolling; mask = state->stopMask; n = 0; @@ -180,13 +180,13 @@ public static unsafe partial class Methods { assert( @params->hashLog - <= (uint)( - (sizeof(nuint) == 4 ? 30 : 31) < 30 - ? sizeof(nuint) == 4 - ? 30 - : 31 - : 30 - ) + <= (uint)( + (sizeof(nuint) == 4 ? 30 : 31) < 30 + ? sizeof(nuint) == 4 + ? 30 + : 31 + : 30 + ) ); if (@params->windowLog > @params->hashLog) { @@ -204,22 +204,22 @@ public static unsafe partial class Methods { @params->hashLog = @params->windowLog - @params->hashRateLog <= 6 ? 6 - : @params->windowLog - @params->hashRateLog - <= (uint)( - (sizeof(nuint) == 4 ? 30 : 31) < 30 - ? sizeof(nuint) == 4 - ? 30 - : 31 - : 30 - ) - ? @params->windowLog - @params->hashRateLog - : (uint)( - (sizeof(nuint) == 4 ? 30 : 31) < 30 - ? sizeof(nuint) == 4 - ? 30 - : 31 - : 30 - ); + : @params->windowLog - @params->hashRateLog + <= (uint)( + (sizeof(nuint) == 4 ? 30 : 31) < 30 + ? sizeof(nuint) == 4 + ? 30 + : 31 + : 30 + ) + ? @params->windowLog - @params->hashRateLog + : (uint)( + (sizeof(nuint) == 4 ? 30 : 31) < 30 + ? sizeof(nuint) == 4 + ? 30 + : 31 + : 30 + ); } if (@params->minMatchLength == 0) @@ -239,9 +239,7 @@ public static unsafe partial class Methods } @params->bucketSizeLog = - @params->bucketSizeLog < @params->hashLog - ? @params->bucketSizeLog - : @params->hashLog; + @params->bucketSizeLog < @params->hashLog ? @params->bucketSizeLog : @params->hashLog; } /** ZSTD_ldm_getTableSize() : @@ -492,13 +490,7 @@ public static unsafe partial class Methods nuint hashed; uint n; numSplits = 0; - hashed = ZSTD_ldm_gear_feed( - &hashState, - ip, - (nuint)(ilimit - ip), - splits, - &numSplits - ); + hashed = ZSTD_ldm_gear_feed(&hashState, ip, (nuint)(ilimit - ip), splits, &numSplits); for (n = 0; n < numSplits; n++) { byte* split = ip + splits[n] - minMatchLength; @@ -507,11 +499,7 @@ public static unsafe partial class Methods candidates[n].split = split; candidates[n].hash = hash; candidates[n].checksum = (uint)(xxhash >> 32); - candidates[n].bucket = ZSTD_ldm_getBucket( - ldmState, - hash, - @params->bucketSizeLog - ); + candidates[n].bucket = ZSTD_ldm_getBucket(ldmState, hash, @params->bucketSizeLog); #if NETCOREAPP3_0_OR_GREATER if (System.Runtime.Intrinsics.X86.Sse.IsSupported) { @@ -523,9 +511,9 @@ public static unsafe partial class Methods for (n = 0; n < numSplits; n++) { nuint forwardMatchLength = 0, - backwardMatchLength = 0, - bestMatchLength = 0, - mLength; + backwardMatchLength = 0, + bestMatchLength = 0, + mLength; uint offset; byte* split = candidates[n].split; uint checksum = candidates[n].checksum; @@ -545,8 +533,8 @@ public static unsafe partial class Methods for (cur = bucket; cur < bucket + entsPerBucket; cur++) { nuint curForwardMatchLength, - curBackwardMatchLength, - curTotalMatchLength; + curBackwardMatchLength, + curTotalMatchLength; if (cur->checksum != checksum || cur->offset <= lowestIndex) { continue; @@ -617,9 +605,7 @@ public static unsafe partial class Methods { rawSeq* seq = rawSeqStore->seq + rawSeqStore->size; if (rawSeqStore->size == rawSeqStore->capacity) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_dstSize_tooSmall)); seq->litLength = (uint)(split - backwardMatchLength - anchor); seq->matchLength = (uint)mLength; seq->offset = offset; @@ -682,13 +668,12 @@ public static unsafe partial class Methods byte* istart = (byte*)src; byte* iend = istart + srcSize; const nuint kMaxChunkSize = 1 << 20; - nuint nbChunks = - srcSize / kMaxChunkSize + (nuint)(srcSize % kMaxChunkSize != 0 ? 1 : 0); + nuint nbChunks = srcSize / kMaxChunkSize + (nuint)(srcSize % kMaxChunkSize != 0 ? 1 : 0); nuint chunk; nuint leftoverSize = 0; assert( unchecked((uint)-1) - (MEM_64bits ? 3500U * (1 << 20) : 2000U * (1 << 20)) - >= kMaxChunkSize + >= kMaxChunkSize ); assert(ldmState->window.nextSrc >= (byte*)src + srcSize); assert(sequences->pos <= sequences->size); diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdmGeartab.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdmGeartab.cs index a828beb2..5edf1197 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdmGeartab.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdLdmGeartab.cs @@ -7,271 +7,271 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public static unsafe partial class Methods { #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_ZSTD_ldm_gearTab => - new ulong[256] - { - 0xf5b8f72c5f77775c, - 0x84935f266b7ac412, - 0xb647ada9ca730ccc, - 0xb065bb4b114fb1de, - 0x34584e7e8c3a9fd0, - 0x4e97e17c6ae26b05, - 0x3a03d743bc99a604, - 0xcecd042422c4044f, - 0x76de76c58524259e, - 0x9c8528f65badeaca, - 0x86563706e2097529, - 0x2902475fa375d889, - 0xafb32a9739a5ebe6, - 0xce2714da3883e639, - 0x21eaf821722e69e, - 0x37b628620b628, - 0x49a8d455d88caf5, - 0x8556d711e6958140, - 0x4f7ae74fc605c1f, - 0x829f0c3468bd3a20, - 0x4ffdc885c625179e, - 0x8473de048a3daf1b, - 0x51008822b05646b2, - 0x69d75d12b2d1cc5f, - 0x8c9d4a19159154bc, - 0xc3cc10f4abbd4003, - 0xd06ddc1cecb97391, - 0xbe48e6e7ed80302e, - 0x3481db31cee03547, - 0xacc3f67cdaa1d210, - 0x65cb771d8c7f96cc, - 0x8eb27177055723dd, - 0xc789950d44cd94be, - 0x934feadc3700b12b, - 0x5e485f11edbdf182, - 0x1e2e2a46fd64767a, - 0x2969ca71d82efa7c, - 0x9d46e9935ebbba2e, - 0xe056b67e05e6822b, - 0x94d73f55739d03a0, - 0xcd7010bdb69b5a03, - 0x455ef9fcd79b82f4, - 0x869cb54a8749c161, - 0x38d1a4fa6185d225, - 0xb475166f94bbe9bb, - 0xa4143548720959f1, - 0x7aed4780ba6b26ba, - 0xd0ce264439e02312, - 0x84366d746078d508, - 0xa8ce973c72ed17be, - 0x21c323a29a430b01, - 0x9962d617e3af80ee, - 0xab0ce91d9c8cf75b, - 0x530e8ee6d19a4dbc, - 0x2ef68c0cf53f5d72, - 0xc03a681640a85506, - 0x496e4e9f9c310967, - 0x78580472b59b14a0, - 0x273824c23b388577, - 0x66bf923ad45cb553, - 0x47ae1a5a2492ba86, - 0x35e304569e229659, - 0x4765182a46870b6f, - 0x6cbab625e9099412, - 0xddac9a2e598522c1, - 0x7172086e666624f2, - 0xdf5003ca503b7837, - 0x88c0c1db78563d09, - 0x58d51865acfc289d, - 0x177671aec65224f1, - 0xfb79d8a241e967d7, - 0x2be1e101cad9a49a, - 0x6625682f6e29186b, - 0x399553457ac06e50, - 0x35dffb4c23abb74, - 0x429db2591f54aade, - 0xc52802a8037d1009, - 0x6acb27381f0b25f3, - 0xf45e2551ee4f823b, - 0x8b0ea2d99580c2f7, - 0x3bed519cbcb4e1e1, - 0xff452823dbb010a, - 0x9d42ed614f3dd267, - 0x5b9313c06257c57b, - 0xa114b8008b5e1442, - 0xc1fe311c11c13d4b, - 0x66e8763ea34c5568, - 0x8b982af1c262f05d, - 0xee8876faaa75fbb7, - 0x8a62a4d0d172bb2a, - 0xc13d94a3b7449a97, - 0x6dbbba9dc15d037c, - 0xc786101f1d92e0f1, - 0xd78681a907a0b79b, - 0xf61aaf2962c9abb9, - 0x2cfd16fcd3cb7ad9, - 0x868c5b6744624d21, - 0x25e650899c74ddd7, - 0xba042af4a7c37463, - 0x4eb1a539465a3eca, - 0xbe09dbf03b05d5ca, - 0x774e5a362b5472ba, - 0x47a1221229d183cd, - 0x504b0ca18ef5a2df, - 0xdffbdfbde2456eb9, - 0x46cd2b2fbee34634, - 0xf2aef8fe819d98c3, - 0x357f5276d4599d61, - 0x24a5483879c453e3, - 0x88026889192b4b9, - 0x28da96671782dbec, - 0x4ef37c40588e9aaa, - 0x8837b90651bc9fb3, - 0xc164f741d3f0e5d6, - 0xbc135a0a704b70ba, - 0x69cd868f7622ada, - 0xbc37ba89e0b9c0ab, - 0x47c14a01323552f6, - 0x4f00794bacee98bb, - 0x7107de7d637a69d5, - 0x88af793bb6f2255e, - 0xf3c6466b8799b598, - 0xc288c616aa7f3b59, - 0x81ca63cf42fca3fd, - 0x88d85ace36a2674b, - 0xd056bd3792389e7, - 0xe55c396c4e9dd32d, - 0xbefb504571e6c0a6, - 0x96ab32115e91e8cc, - 0xbf8acb18de8f38d1, - 0x66dae58801672606, - 0x833b6017872317fb, - 0xb87c16f2d1c92864, - 0xdb766a74e58b669c, - 0x89659f85c61417be, - 0xc8daad856011ea0c, - 0x76a4b565b6fe7eae, - 0xa469d085f6237312, - 0xaaf0365683a3e96c, - 0x4dbb746f8424f7b8, - 0x638755af4e4acc1, - 0x3d7807f5bde64486, - 0x17be6d8f5bbb7639, - 0x903f0cd44dc35dc, - 0x67b672eafdf1196c, - 0xa676ff93ed4c82f1, - 0x521d1004c5053d9d, - 0x37ba9ad09ccc9202, - 0x84e54d297aacfb51, - 0xa0b4b776a143445, - 0x820d471e20b348e, - 0x1874383cb83d46dc, - 0x97edeec7a1efe11c, - 0xb330e50b1bdc42aa, - 0x1dd91955ce70e032, - 0xa514cdb88f2939d5, - 0x2791233fd90db9d3, - 0x7b670a4cc50f7a9b, - 0x77c07d2a05c6dfa5, - 0xe3778b6646d0a6fa, - 0xb39c8eda47b56749, - 0x933ed448addbef28, - 0xaf846af6ab7d0bf4, - 0xe5af208eb666e49, - 0x5e6622f73534cd6a, - 0x297daeca42ef5b6e, - 0x862daef3d35539a6, - 0xe68722498f8e1ea9, - 0x981c53093dc0d572, - 0xfa09b0bfbf86fbf5, - 0x30b1e96166219f15, - 0x70e7d466bdc4fb83, - 0x5a66736e35f2a8e9, - 0xcddb59d2b7c1baef, - 0xd6c7d247d26d8996, - 0xea4e39eac8de1ba3, - 0x539c8bb19fa3aff2, - 0x9f90e4c5fd508d8, - 0xa34e5956fbaf3385, - 0x2e2f8e151d3ef375, - 0x173691e9b83faec1, - 0xb85a8d56bf016379, - 0x8382381267408ae3, - 0xb90f901bbdc0096d, - 0x7c6ad32933bcec65, - 0x76bb5e2f2c8ad595, - 0x390f851a6cf46d28, - 0xc3e6064da1c2da72, - 0xc52a0c101cfa5389, - 0xd78eaf84a3fbc530, - 0x3781b9e2288b997e, - 0x73c2f6dea83d05c4, - 0x4228e364c5b5ed7, - 0x9d7a3edf0da43911, - 0x8edcfeda24686756, - 0x5e7667a7b7a9b3a1, - 0x4c4f389fa143791d, - 0xb08bc1023da7cddc, - 0x7ab4be3ae529b1cc, - 0x754e6132dbe74ff9, - 0x71635442a839df45, - 0x2f6fb1643fbe52de, - 0x961e0a42cf7a8177, - 0xf3b45d83d89ef2ea, - 0xee3de4cf4a6e3e9b, - 0xcd6848542c3295e7, - 0xe4cee1664c78662f, - 0x9947548b474c68c4, - 0x25d73777a5ed8b0b, - 0xc915b1d636b7fc, - 0x21c2ba75d9b0d2da, - 0x5f6b5dcf608a64a1, - 0xdcf333255ff9570c, - 0x633b922418ced4ee, - 0xc136dde0b004b34a, - 0x58cc83b05d4b2f5a, - 0x5eb424dda28e42d2, - 0x62df47369739cd98, - 0xb4e0b42485e4ce17, - 0x16e1f0c1f9a8d1e7, - 0x8ec3916707560ebf, - 0x62ba6e2df2cc9db3, - 0xcbf9f4ff77d83a16, - 0x78d9d7d07d2bbcc4, - 0xef554ce1e02c41f4, - 0x8d7581127eccf94d, - 0xa9b53336cb3c8a05, - 0x38c42c0bf45c4f91, - 0x640893cdf4488863, - 0x80ec34bc575ea568, - 0x39f324f5b48eaa40, - 0xe9d9ed1f8eff527f, - 0x9224fc058cc5a214, - 0xbaba00b04cfe7741, - 0x309a9f120fcf52af, - 0xa558f3ec65626212, - 0x424bec8b7adabe2f, - 0x41622513a6aea433, - 0xb88da2d5324ca798, - 0xd287733b245528a4, - 0x9a44697e6d68aec3, - 0x7b1093be2f49bb28, - 0x50bbec632e3d8aad, - 0x6cd90723e1ea8283, - 0x897b9e7431b02bf3, - 0x219efdcb338a7047, - 0x3b0311f0a27c0656, - 0xdb17bf91c0db96e7, - 0x8cd4fd6b4e85a5b2, - 0xfab071054ba6409d, - 0x40d6fe831fa9dfd9, - 0xaf358debad7d791e, - 0xeb8d0e25a65e3e58, - 0xbbcbd3df14e08580, - 0xcf751f27ecdab2b, - 0x2b4da14f2613d8f4, - }; - private static ulong* ZSTD_ldm_gearTab => - (ulong*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_ZSTD_ldm_gearTab) - ); + private static ReadOnlySpan Span_ZSTD_ldm_gearTab => + new ulong[256] + { + 0xf5b8f72c5f77775c, + 0x84935f266b7ac412, + 0xb647ada9ca730ccc, + 0xb065bb4b114fb1de, + 0x34584e7e8c3a9fd0, + 0x4e97e17c6ae26b05, + 0x3a03d743bc99a604, + 0xcecd042422c4044f, + 0x76de76c58524259e, + 0x9c8528f65badeaca, + 0x86563706e2097529, + 0x2902475fa375d889, + 0xafb32a9739a5ebe6, + 0xce2714da3883e639, + 0x21eaf821722e69e, + 0x37b628620b628, + 0x49a8d455d88caf5, + 0x8556d711e6958140, + 0x4f7ae74fc605c1f, + 0x829f0c3468bd3a20, + 0x4ffdc885c625179e, + 0x8473de048a3daf1b, + 0x51008822b05646b2, + 0x69d75d12b2d1cc5f, + 0x8c9d4a19159154bc, + 0xc3cc10f4abbd4003, + 0xd06ddc1cecb97391, + 0xbe48e6e7ed80302e, + 0x3481db31cee03547, + 0xacc3f67cdaa1d210, + 0x65cb771d8c7f96cc, + 0x8eb27177055723dd, + 0xc789950d44cd94be, + 0x934feadc3700b12b, + 0x5e485f11edbdf182, + 0x1e2e2a46fd64767a, + 0x2969ca71d82efa7c, + 0x9d46e9935ebbba2e, + 0xe056b67e05e6822b, + 0x94d73f55739d03a0, + 0xcd7010bdb69b5a03, + 0x455ef9fcd79b82f4, + 0x869cb54a8749c161, + 0x38d1a4fa6185d225, + 0xb475166f94bbe9bb, + 0xa4143548720959f1, + 0x7aed4780ba6b26ba, + 0xd0ce264439e02312, + 0x84366d746078d508, + 0xa8ce973c72ed17be, + 0x21c323a29a430b01, + 0x9962d617e3af80ee, + 0xab0ce91d9c8cf75b, + 0x530e8ee6d19a4dbc, + 0x2ef68c0cf53f5d72, + 0xc03a681640a85506, + 0x496e4e9f9c310967, + 0x78580472b59b14a0, + 0x273824c23b388577, + 0x66bf923ad45cb553, + 0x47ae1a5a2492ba86, + 0x35e304569e229659, + 0x4765182a46870b6f, + 0x6cbab625e9099412, + 0xddac9a2e598522c1, + 0x7172086e666624f2, + 0xdf5003ca503b7837, + 0x88c0c1db78563d09, + 0x58d51865acfc289d, + 0x177671aec65224f1, + 0xfb79d8a241e967d7, + 0x2be1e101cad9a49a, + 0x6625682f6e29186b, + 0x399553457ac06e50, + 0x35dffb4c23abb74, + 0x429db2591f54aade, + 0xc52802a8037d1009, + 0x6acb27381f0b25f3, + 0xf45e2551ee4f823b, + 0x8b0ea2d99580c2f7, + 0x3bed519cbcb4e1e1, + 0xff452823dbb010a, + 0x9d42ed614f3dd267, + 0x5b9313c06257c57b, + 0xa114b8008b5e1442, + 0xc1fe311c11c13d4b, + 0x66e8763ea34c5568, + 0x8b982af1c262f05d, + 0xee8876faaa75fbb7, + 0x8a62a4d0d172bb2a, + 0xc13d94a3b7449a97, + 0x6dbbba9dc15d037c, + 0xc786101f1d92e0f1, + 0xd78681a907a0b79b, + 0xf61aaf2962c9abb9, + 0x2cfd16fcd3cb7ad9, + 0x868c5b6744624d21, + 0x25e650899c74ddd7, + 0xba042af4a7c37463, + 0x4eb1a539465a3eca, + 0xbe09dbf03b05d5ca, + 0x774e5a362b5472ba, + 0x47a1221229d183cd, + 0x504b0ca18ef5a2df, + 0xdffbdfbde2456eb9, + 0x46cd2b2fbee34634, + 0xf2aef8fe819d98c3, + 0x357f5276d4599d61, + 0x24a5483879c453e3, + 0x88026889192b4b9, + 0x28da96671782dbec, + 0x4ef37c40588e9aaa, + 0x8837b90651bc9fb3, + 0xc164f741d3f0e5d6, + 0xbc135a0a704b70ba, + 0x69cd868f7622ada, + 0xbc37ba89e0b9c0ab, + 0x47c14a01323552f6, + 0x4f00794bacee98bb, + 0x7107de7d637a69d5, + 0x88af793bb6f2255e, + 0xf3c6466b8799b598, + 0xc288c616aa7f3b59, + 0x81ca63cf42fca3fd, + 0x88d85ace36a2674b, + 0xd056bd3792389e7, + 0xe55c396c4e9dd32d, + 0xbefb504571e6c0a6, + 0x96ab32115e91e8cc, + 0xbf8acb18de8f38d1, + 0x66dae58801672606, + 0x833b6017872317fb, + 0xb87c16f2d1c92864, + 0xdb766a74e58b669c, + 0x89659f85c61417be, + 0xc8daad856011ea0c, + 0x76a4b565b6fe7eae, + 0xa469d085f6237312, + 0xaaf0365683a3e96c, + 0x4dbb746f8424f7b8, + 0x638755af4e4acc1, + 0x3d7807f5bde64486, + 0x17be6d8f5bbb7639, + 0x903f0cd44dc35dc, + 0x67b672eafdf1196c, + 0xa676ff93ed4c82f1, + 0x521d1004c5053d9d, + 0x37ba9ad09ccc9202, + 0x84e54d297aacfb51, + 0xa0b4b776a143445, + 0x820d471e20b348e, + 0x1874383cb83d46dc, + 0x97edeec7a1efe11c, + 0xb330e50b1bdc42aa, + 0x1dd91955ce70e032, + 0xa514cdb88f2939d5, + 0x2791233fd90db9d3, + 0x7b670a4cc50f7a9b, + 0x77c07d2a05c6dfa5, + 0xe3778b6646d0a6fa, + 0xb39c8eda47b56749, + 0x933ed448addbef28, + 0xaf846af6ab7d0bf4, + 0xe5af208eb666e49, + 0x5e6622f73534cd6a, + 0x297daeca42ef5b6e, + 0x862daef3d35539a6, + 0xe68722498f8e1ea9, + 0x981c53093dc0d572, + 0xfa09b0bfbf86fbf5, + 0x30b1e96166219f15, + 0x70e7d466bdc4fb83, + 0x5a66736e35f2a8e9, + 0xcddb59d2b7c1baef, + 0xd6c7d247d26d8996, + 0xea4e39eac8de1ba3, + 0x539c8bb19fa3aff2, + 0x9f90e4c5fd508d8, + 0xa34e5956fbaf3385, + 0x2e2f8e151d3ef375, + 0x173691e9b83faec1, + 0xb85a8d56bf016379, + 0x8382381267408ae3, + 0xb90f901bbdc0096d, + 0x7c6ad32933bcec65, + 0x76bb5e2f2c8ad595, + 0x390f851a6cf46d28, + 0xc3e6064da1c2da72, + 0xc52a0c101cfa5389, + 0xd78eaf84a3fbc530, + 0x3781b9e2288b997e, + 0x73c2f6dea83d05c4, + 0x4228e364c5b5ed7, + 0x9d7a3edf0da43911, + 0x8edcfeda24686756, + 0x5e7667a7b7a9b3a1, + 0x4c4f389fa143791d, + 0xb08bc1023da7cddc, + 0x7ab4be3ae529b1cc, + 0x754e6132dbe74ff9, + 0x71635442a839df45, + 0x2f6fb1643fbe52de, + 0x961e0a42cf7a8177, + 0xf3b45d83d89ef2ea, + 0xee3de4cf4a6e3e9b, + 0xcd6848542c3295e7, + 0xe4cee1664c78662f, + 0x9947548b474c68c4, + 0x25d73777a5ed8b0b, + 0xc915b1d636b7fc, + 0x21c2ba75d9b0d2da, + 0x5f6b5dcf608a64a1, + 0xdcf333255ff9570c, + 0x633b922418ced4ee, + 0xc136dde0b004b34a, + 0x58cc83b05d4b2f5a, + 0x5eb424dda28e42d2, + 0x62df47369739cd98, + 0xb4e0b42485e4ce17, + 0x16e1f0c1f9a8d1e7, + 0x8ec3916707560ebf, + 0x62ba6e2df2cc9db3, + 0xcbf9f4ff77d83a16, + 0x78d9d7d07d2bbcc4, + 0xef554ce1e02c41f4, + 0x8d7581127eccf94d, + 0xa9b53336cb3c8a05, + 0x38c42c0bf45c4f91, + 0x640893cdf4488863, + 0x80ec34bc575ea568, + 0x39f324f5b48eaa40, + 0xe9d9ed1f8eff527f, + 0x9224fc058cc5a214, + 0xbaba00b04cfe7741, + 0x309a9f120fcf52af, + 0xa558f3ec65626212, + 0x424bec8b7adabe2f, + 0x41622513a6aea433, + 0xb88da2d5324ca798, + 0xd287733b245528a4, + 0x9a44697e6d68aec3, + 0x7b1093be2f49bb28, + 0x50bbec632e3d8aad, + 0x6cd90723e1ea8283, + 0x897b9e7431b02bf3, + 0x219efdcb338a7047, + 0x3b0311f0a27c0656, + 0xdb17bf91c0db96e7, + 0x8cd4fd6b4e85a5b2, + 0xfab071054ba6409d, + 0x40d6fe831fa9dfd9, + 0xaf358debad7d791e, + 0xeb8d0e25a65e3e58, + 0xbbcbd3df14e08580, + 0xcf751f27ecdab2b, + 0x2b4da14f2613d8f4, + }; + private static ulong* ZSTD_ldm_gearTab => + (ulong*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_ZSTD_ldm_gearTab) + ); #else private static readonly ulong* ZSTD_ldm_gearTab = GetArrayPointer( diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdOpt.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdOpt.cs index 7c8a98ca..4b05bb17 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdOpt.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdOpt.cs @@ -42,9 +42,7 @@ public static unsafe partial class Methods { if (ZSTD_compressedLiterals(optPtr) != 0) optPtr->litSumBasePrice = - optLevel != 0 - ? ZSTD_fracWeight(optPtr->litSum) - : ZSTD_bitWeight(optPtr->litSum); + optLevel != 0 ? ZSTD_fracWeight(optPtr->litSum) : ZSTD_bitWeight(optPtr->litSum); optPtr->litLengthSumBasePrice = optLevel != 0 ? ZSTD_fracWeight(optPtr->litLengthSum) @@ -79,7 +77,7 @@ public static unsafe partial class Methods ) { uint s, - sum = 0; + sum = 0; assert(shift < 30); for (s = 0; s < lastEltIndex + 1; s++) { @@ -115,51 +113,51 @@ public static unsafe partial class Methods } #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_baseLLfreqs => - new uint[36] - { - 4, - 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - }; - private static uint* baseLLfreqs => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_baseLLfreqs) - ); + private static ReadOnlySpan Span_baseLLfreqs => + new uint[36] + { + 4, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + }; + private static uint* baseLLfreqs => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_baseLLfreqs) + ); #else private static readonly uint* baseLLfreqs = GetArrayPointer( @@ -205,47 +203,47 @@ public static unsafe partial class Methods ); #endif #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_baseOFCfreqs => - new uint[32] - { - 6, - 2, - 1, - 1, - 2, - 3, - 4, - 4, - 4, - 3, - 2, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - 1, - }; - private static uint* baseOFCfreqs => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_baseOFCfreqs) - ); + private static ReadOnlySpan Span_baseOFCfreqs => + new uint[32] + { + 6, + 2, + 1, + 1, + 2, + 3, + 4, + 4, + 4, + 3, + 2, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + 1, + }; + private static uint* baseOFCfreqs => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_baseOFCfreqs) + ); #else private static readonly uint* baseOFCfreqs = GetArrayPointer( @@ -481,12 +479,12 @@ public static unsafe partial class Methods { uint llCode = ZSTD_LLcode(litLength); return (uint)(LL_bits[llCode] * (1 << 8)) - + optPtr->litLengthSumBasePrice - - ( - optLevel != 0 - ? ZSTD_fracWeight(optPtr->litLengthFreq[llCode]) - : ZSTD_bitWeight(optPtr->litLengthFreq[llCode]) - ); + + optPtr->litLengthSumBasePrice + - ( + optLevel != 0 + ? ZSTD_fracWeight(optPtr->litLengthFreq[llCode]) + : ZSTD_bitWeight(optPtr->litLengthFreq[llCode]) + ); } } @@ -510,7 +508,7 @@ public static unsafe partial class Methods assert(matchLength >= 3); if (optPtr->priceType == ZSTD_OptPrice_e.zop_predef) return (optLevel != 0 ? ZSTD_fracWeight(mlBase) : ZSTD_bitWeight(mlBase)) - + (16 + offCode) * (1 << 8); + + (16 + offCode) * (1 << 8); price = offCode * (1 << 8) + ( @@ -649,7 +647,7 @@ public static unsafe partial class Methods uint btMask = (uint)((1 << (int)btLog) - 1); uint matchIndex = hashTable[h]; nuint commonLengthSmaller = 0, - commonLengthLarger = 0; + commonLengthLarger = 0; byte* @base = ms->window.@base; byte* dictBase = ms->window.dictBase; uint dictLimit = ms->window.dictLimit; @@ -678,9 +676,7 @@ public static unsafe partial class Methods uint* nextPtr = bt + 2 * (matchIndex & btMask); /* guaranteed minimum nb of common bytes */ nuint matchLength = - commonLengthSmaller < commonLengthLarger - ? commonLengthSmaller - : commonLengthLarger; + commonLengthSmaller < commonLengthLarger ? commonLengthSmaller : commonLengthLarger; assert(matchIndex < curr); if (extDict == 0 || matchIndex + matchLength >= dictLimit) { @@ -786,13 +782,7 @@ public static unsafe partial class Methods /* used in ZSTD_loadDictionaryContent() */ private static void ZSTD_updateTree(ZSTD_MatchState_t* ms, byte* ip, byte* iend) { - ZSTD_updateTree_internal( - ms, - ip, - iend, - ms->cParams.minMatch, - ZSTD_dictMode_e.ZSTD_noDict - ); + ZSTD_updateTree_internal(ms, ip, iend, ms->cParams.minMatch, ZSTD_dictMode_e.ZSTD_noDict); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -823,7 +813,7 @@ public static unsafe partial class Methods uint btLog = cParams->chainLog - 1; uint btMask = (1U << (int)btLog) - 1; nuint commonLengthSmaller = 0, - commonLengthLarger = 0; + commonLengthLarger = 0; byte* dictBase = ms->window.dictBase; uint dictLimit = ms->window.dictLimit; byte* dictEnd = dictBase + dictLimit; @@ -843,10 +833,8 @@ public static unsafe partial class Methods dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? ms->dictMatchState : null; ZSTD_compressionParameters* dmsCParams = dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? &dms->cParams : null; - byte* dmsBase = - dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? dms->window.@base : null; - byte* dmsEnd = - dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? dms->window.nextSrc : null; + byte* dmsBase = dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? dms->window.@base : null; + byte* dmsEnd = dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? dms->window.nextSrc : null; uint dmsHighLimit = dictMode == ZSTD_dictMode_e.ZSTD_dictMatchState ? (uint)(dmsEnd - dmsBase) : 0; uint dmsLowLimit = @@ -880,7 +868,7 @@ public static unsafe partial class Methods if ( repIndex >= windowLow && ZSTD_readMINMATCH(ip, minMatch) - == ZSTD_readMINMATCH(ip - repOffset, minMatch) + == ZSTD_readMINMATCH(ip - repOffset, minMatch) ) { repLen = @@ -901,8 +889,7 @@ public static unsafe partial class Methods (repOffset - 1 < curr - windowLow ? 1 : 0) & ZSTD_index_overlap_check(dictLimit, repIndex) ) != 0 - && ZSTD_readMINMATCH(ip, minMatch) - == ZSTD_readMINMATCH(repMatch, minMatch) + && ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch) ) { repLen = @@ -921,8 +908,7 @@ public static unsafe partial class Methods (repOffset - 1 < curr - (dmsLowLimit + dmsIndexDelta) ? 1 : 0) & ZSTD_index_overlap_check(dictLimit, repIndex) ) != 0 - && ZSTD_readMINMATCH(ip, minMatch) - == ZSTD_readMINMATCH(repMatch, minMatch) + && ZSTD_readMINMATCH(ip, minMatch) == ZSTD_readMINMATCH(repMatch, minMatch) ) { repLen = @@ -998,9 +984,7 @@ public static unsafe partial class Methods byte* match; /* guaranteed minimum nb of common bytes */ nuint matchLength = - commonLengthSmaller < commonLengthLarger - ? commonLengthSmaller - : commonLengthLarger; + commonLengthSmaller < commonLengthLarger ? commonLengthSmaller : commonLengthLarger; assert(curr > matchIndex); if ( dictMode == ZSTD_dictMode_e.ZSTD_noDict @@ -1480,31 +1464,32 @@ public static unsafe partial class Methods ); } - private static readonly ZSTD_getAllMatchesFn[][] getAllMatchesFns = - new ZSTD_getAllMatchesFn[3][] + private static readonly ZSTD_getAllMatchesFn[][] getAllMatchesFns = new ZSTD_getAllMatchesFn[ + 3 + ][] + { + new ZSTD_getAllMatchesFn[4] { - new ZSTD_getAllMatchesFn[4] - { - ZSTD_btGetAllMatches_noDict_3, - ZSTD_btGetAllMatches_noDict_4, - ZSTD_btGetAllMatches_noDict_5, - ZSTD_btGetAllMatches_noDict_6, - }, - new ZSTD_getAllMatchesFn[4] - { - ZSTD_btGetAllMatches_extDict_3, - ZSTD_btGetAllMatches_extDict_4, - ZSTD_btGetAllMatches_extDict_5, - ZSTD_btGetAllMatches_extDict_6, - }, - new ZSTD_getAllMatchesFn[4] - { - ZSTD_btGetAllMatches_dictMatchState_3, - ZSTD_btGetAllMatches_dictMatchState_4, - ZSTD_btGetAllMatches_dictMatchState_5, - ZSTD_btGetAllMatches_dictMatchState_6, - }, - }; + ZSTD_btGetAllMatches_noDict_3, + ZSTD_btGetAllMatches_noDict_4, + ZSTD_btGetAllMatches_noDict_5, + ZSTD_btGetAllMatches_noDict_6, + }, + new ZSTD_getAllMatchesFn[4] + { + ZSTD_btGetAllMatches_extDict_3, + ZSTD_btGetAllMatches_extDict_4, + ZSTD_btGetAllMatches_extDict_5, + ZSTD_btGetAllMatches_extDict_6, + }, + new ZSTD_getAllMatchesFn[4] + { + ZSTD_btGetAllMatches_dictMatchState_3, + ZSTD_btGetAllMatches_dictMatchState_4, + ZSTD_btGetAllMatches_dictMatchState_5, + ZSTD_btGetAllMatches_dictMatchState_6, + }, + }; private static ZSTD_getAllMatchesFn ZSTD_selectBtGetAllMatches( ZSTD_MatchState_t* ms, @@ -1524,10 +1509,7 @@ public static unsafe partial class Methods * Moves forward in @rawSeqStore by @nbBytes, * which will update the fields 'pos' and 'posInSequence'. */ - private static void ZSTD_optLdm_skipRawSeqStoreBytes( - RawSeqStore_t* rawSeqStore, - nuint nbBytes - ) + private static void ZSTD_optLdm_skipRawSeqStoreBytes(RawSeqStore_t* rawSeqStore, nuint nbBytes) { uint currPos = (uint)(rawSeqStore->posInSequence + nbBytes); while (currPos != 0 && rawSeqStore->pos < rawSeqStore->size) @@ -1581,8 +1563,7 @@ public static unsafe partial class Methods : 0; matchBytesRemaining = literalsBytesRemaining == 0 - ? currSeq.matchLength - - ((uint)optLdm->seqStore.posInSequence - currSeq.litLength) + ? currSeq.matchLength - ((uint)optLdm->seqStore.posInSequence - currSeq.litLength) : currSeq.matchLength; if (literalsBytesRemaining >= blockBytesRemaining) { @@ -1598,10 +1579,7 @@ public static unsafe partial class Methods if (optLdm->endPosInBlock > currBlockEndPos) { optLdm->endPosInBlock = currBlockEndPos; - ZSTD_optLdm_skipRawSeqStoreBytes( - &optLdm->seqStore, - currBlockEndPos - currPosInBlock - ); + ZSTD_optLdm_skipRawSeqStoreBytes(&optLdm->seqStore, currBlockEndPos - currPosInBlock); } else { @@ -1724,7 +1702,7 @@ public static unsafe partial class Methods while (ip < ilimit) { uint cur, - last_pos = 0; + last_pos = 0; { uint litlen = (uint)(ip - anchor); uint ll0 = litlen == 0 ? 1U : 0U; @@ -1798,8 +1776,7 @@ public static unsafe partial class Methods opt[pos].off = offBase; opt[pos].litlen = 0; opt[pos].price = - sequencePrice - + (int)ZSTD_litLengthPrice(0, optStatePtr, optLevel); + sequencePrice + (int)ZSTD_litLengthPrice(0, optStatePtr, optLevel); } } @@ -1832,8 +1809,8 @@ public static unsafe partial class Methods optLevel >= 1 && prevMatch.litlen == 0 && (int)ZSTD_litLengthPrice(1, optStatePtr, optLevel) - - (int)ZSTD_litLengthPrice(1 - 1, optStatePtr, optLevel) - < 0 + - (int)ZSTD_litLengthPrice(1 - 1, optStatePtr, optLevel) + < 0 && ip + cur < iend ) { @@ -2143,14 +2120,7 @@ public static unsafe partial class Methods assert(seqStore->sequences == seqStore->sequencesStart); assert(ms->window.dictLimit == ms->window.lowLimit); assert(ms->window.dictLimit - ms->nextToUpdate <= 1); - ZSTD_compressBlock_opt2( - ms, - seqStore, - tmpRep, - src, - srcSize, - ZSTD_dictMode_e.ZSTD_noDict - ); + ZSTD_compressBlock_opt2(ms, seqStore, tmpRep, src, srcSize, ZSTD_dictMode_e.ZSTD_noDict); ZSTD_resetSeqStore(seqStore); ms->window.@base -= srcSize; ms->window.dictLimit += (uint)srcSize; diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdPresplit.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdPresplit.cs index 51f0fd22..e0d13921 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdPresplit.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdPresplit.cs @@ -163,12 +163,12 @@ public static unsafe partial class Methods (delegate* managed)(&ZSTD_recordFingerprint_1), }; #if NET7_0_OR_GREATER - private static ReadOnlySpan Span_hashParams => new uint[4] { 8, 9, 10, 10 }; - private static uint* hashParams => - (uint*) - System.Runtime.CompilerServices.Unsafe.AsPointer( - ref MemoryMarshal.GetReference(Span_hashParams) - ); + private static ReadOnlySpan Span_hashParams => new uint[4] { 8, 9, 10, 10 }; + private static uint* hashParams => + (uint*) + System.Runtime.CompilerServices.Unsafe.AsPointer( + ref MemoryMarshal.GetReference(Span_hashParams) + ); #else private static readonly uint* hashParams = GetArrayPointer(new uint[4] { 8, 9, 10, 10 }); @@ -245,8 +245,7 @@ public static unsafe partial class Methods ) { FPStats* fpstats = (FPStats*)workspace; - Fingerprint* middleEvents = (Fingerprint*) - (void*)((sbyte*)workspace + 512 * sizeof(uint)); + Fingerprint* middleEvents = (Fingerprint*)(void*)((sbyte*)workspace + 512 * sizeof(uint)); assert(blockSize == 128 << 10); assert(workspace != null); assert((nuint)workspace % (nuint)Math.Max(sizeof(uint), sizeof(ulong)) == 0); diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdmtCompress.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdmtCompress.cs index 7d955bb5..2a21c323 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdmtCompress.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ZstdmtCompress.cs @@ -193,10 +193,7 @@ public static unsafe partial class Methods ZSTDMT_setBufferSize(seqPool, nbSeq * (nuint)sizeof(rawSeq)); } - private static ZSTDMT_bufferPool_s* ZSTDMT_createSeqPool( - uint nbWorkers, - ZSTD_customMem cMem - ) + private static ZSTDMT_bufferPool_s* ZSTDMT_createSeqPool(uint nbWorkers, ZSTD_customMem cMem) { ZSTDMT_bufferPool_s* seqPool = ZSTDMT_createBufferPool(nbWorkers, cMem); if (seqPool == null) @@ -270,10 +267,7 @@ public static unsafe partial class Methods return cctxPool; } - private static ZSTDMT_CCtxPool* ZSTDMT_expandCCtxPool( - ZSTDMT_CCtxPool* srcPool, - int nbWorkers - ) + private static ZSTDMT_CCtxPool* ZSTDMT_expandCCtxPool(ZSTDMT_CCtxPool* srcPool, int nbWorkers) { if (srcPool == null) return null; @@ -381,19 +375,13 @@ public static unsafe partial class Methods ) { ZSTD_customFree(serialState->ldmState.hashTable, cMem); - serialState->ldmState.hashTable = (ldmEntry_t*)ZSTD_customMalloc( - hashSize, - cMem - ); + serialState->ldmState.hashTable = (ldmEntry_t*)ZSTD_customMalloc(hashSize, cMem); } if (serialState->ldmState.bucketOffsets == null || prevBucketLog < bucketLog) { ZSTD_customFree(serialState->ldmState.bucketOffsets, cMem); - serialState->ldmState.bucketOffsets = (byte*)ZSTD_customMalloc( - numBuckets, - cMem - ); + serialState->ldmState.bucketOffsets = (byte*)ZSTD_customMalloc(numBuckets, cMem); } if ( @@ -473,9 +461,9 @@ public static unsafe partial class Methods nuint error; assert( seqStore->seq != null - && seqStore->pos == 0 - && seqStore->size == 0 - && seqStore->capacity > 0 + && seqStore->pos == 0 + && seqStore->size == 0 + && seqStore->capacity > 0 ); assert(src.size <= serialState->@params.jobSize); ZSTD_window_update(&serialState->ldmState.window, src.start, src.size, 0); @@ -510,9 +498,7 @@ public static unsafe partial class Methods { if (seqStore->size > 0) { - assert( - serialState->@params.ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable - ); + assert(serialState->@params.ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable); assert(jobCCtx != null); ZSTD_referenceExternalSequences(jobCCtx, seqStore->seq, seqStore->size); } @@ -565,9 +551,7 @@ public static unsafe partial class Methods if (dstBuff.start == null) { SynchronizationWrapper.Enter(&job->job_mutex); - job->cSize = unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation) - ); + job->cSize = unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); SynchronizationWrapper.Exit(&job->job_mutex); goto _endJob; } @@ -734,18 +718,10 @@ public static unsafe partial class Methods { nuint lastBlockSize1 = job->src.size & chunkSize - 1; nuint lastBlockSize = - lastBlockSize1 == 0 && job->src.size >= chunkSize - ? chunkSize - : lastBlockSize1; + lastBlockSize1 == 0 && job->src.size >= chunkSize ? chunkSize : lastBlockSize1; nuint cSize = job->lastJob != 0 - ? ZSTD_compressEnd_public( - cctx, - op, - (nuint)(oend - op), - ip, - lastBlockSize - ) + ? ZSTD_compressEnd_public(cctx, op, (nuint)(oend - op), ip, lastBlockSize) : ZSTD_compressContinue_public( cctx, op, @@ -863,10 +839,7 @@ public static unsafe partial class Methods /* ZSTDMT_CCtxParam_setNbWorkers(): * Internal use only */ - private static nuint ZSTDMT_CCtxParam_setNbWorkers( - ZSTD_CCtx_params_s* @params, - uint nbWorkers - ) + private static nuint ZSTDMT_CCtxParam_setNbWorkers(ZSTD_CCtx_params_s* @params, uint nbWorkers) { return ZSTD_CCtxParams_setParameter( @params, @@ -961,11 +934,7 @@ public static unsafe partial class Methods void* mutex = mtctx->jobs[jobID].job_mutex; void* cond = mtctx->jobs[jobID].job_cond; ZSTDMT_releaseBuffer(mtctx->bufPool, mtctx->jobs[jobID].dstBuff); - mtctx->jobs[jobID] = new ZSTDMT_jobDescription - { - job_mutex = mutex, - job_cond = cond, - }; + mtctx->jobs[jobID] = new ZSTDMT_jobDescription { job_mutex = mutex, job_cond = cond }; } mtctx->inBuff.buffer = g_nullBuffer; @@ -1013,13 +982,13 @@ public static unsafe partial class Methods if (mtctx == null) return 0; return (nuint)sizeof(ZSTDMT_CCtx_s) - + POOL_sizeof(mtctx->factory) - + ZSTDMT_sizeof_bufferPool(mtctx->bufPool) - + (mtctx->jobIDMask + 1) * (uint)sizeof(ZSTDMT_jobDescription) - + ZSTDMT_sizeof_CCtxPool(mtctx->cctxPool) - + ZSTDMT_sizeof_seqPool(mtctx->seqPool) - + ZSTD_sizeof_CDict(mtctx->cdictLocal) - + mtctx->roundBuff.capacity; + + POOL_sizeof(mtctx->factory) + + ZSTDMT_sizeof_bufferPool(mtctx->bufPool) + + (mtctx->jobIDMask + 1) * (uint)sizeof(ZSTDMT_jobDescription) + + ZSTDMT_sizeof_CCtxPool(mtctx->cctxPool) + + ZSTDMT_sizeof_seqPool(mtctx->seqPool) + + ZSTD_sizeof_CDict(mtctx->cdictLocal) + + mtctx->roundBuff.capacity; } /* ZSTDMT_resize() : @@ -1206,9 +1175,7 @@ public static unsafe partial class Methods private static nuint ZSTDMT_computeOverlapSize(ZSTD_CCtx_params_s* @params) { int overlapRLog = 9 - ZSTDMT_overlapLog(@params->overlapLog, @params->cParams.strategy); - int ovLog = (int)( - overlapRLog >= 8 ? 0 : @params->cParams.windowLog - (uint)overlapRLog - ); + int ovLog = (int)(overlapRLog >= 8 ? 0 : @params->cParams.windowLog - (uint)overlapRLog); assert(0 <= overlapRLog && overlapRLog <= 8); if (@params->ldmParams.enableLdm == ZSTD_paramSwitch_e.ZSTD_ps_enable) { @@ -1288,9 +1255,7 @@ public static unsafe partial class Methods mtctx->targetSectionSize = @params.jobSize; if (mtctx->targetSectionSize == 0) { - mtctx->targetSectionSize = (nuint)( - 1UL << (int)ZSTDMT_computeTargetJobLog(&@params) - ); + mtctx->targetSectionSize = (nuint)(1UL << (int)ZSTDMT_computeTargetJobLog(&@params)); } assert( @@ -1326,12 +1291,9 @@ public static unsafe partial class Methods nuint nbSlackBuffers = (nuint)(2 + (mtctx->targetPrefixSize > 0 ? 1 : 0)); nuint slackSize = mtctx->targetSectionSize * nbSlackBuffers; /* Compute the total size, and always have enough slack */ - nuint nbWorkers = (nuint)( - mtctx->@params.nbWorkers > 1 ? mtctx->@params.nbWorkers : 1 - ); + nuint nbWorkers = (nuint)(mtctx->@params.nbWorkers > 1 ? mtctx->@params.nbWorkers : 1); nuint sectionsSize = mtctx->targetSectionSize * nbWorkers; - nuint capacity = - (windowSize > sectionsSize ? windowSize : sectionsSize) + slackSize; + nuint capacity = (windowSize > sectionsSize ? windowSize : sectionsSize) + slackSize; if (mtctx->roundBuff.capacity < capacity) { if (mtctx->roundBuff.buffer != null) @@ -1340,9 +1302,7 @@ public static unsafe partial class Methods if (mtctx->roundBuff.buffer == null) { mtctx->roundBuff.capacity = 0; - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); } mtctx->roundBuff.capacity = capacity; @@ -1381,9 +1341,7 @@ public static unsafe partial class Methods ); mtctx->cdict = mtctx->cdictLocal; if (mtctx->cdictLocal == null) - return unchecked( - (nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation) - ); + return unchecked((nuint)(-(int)ZSTD_ErrorCode.ZSTD_error_memory_allocation)); } } else @@ -1441,9 +1399,7 @@ public static unsafe partial class Methods int endFrame = endOp == ZSTD_EndDirective.ZSTD_e_end ? 1 : 0; if (mtctx->nextJobID > mtctx->doneJobID + mtctx->jobIDMask) { - assert( - (mtctx->nextJobID & mtctx->jobIDMask) == (mtctx->doneJobID & mtctx->jobIDMask) - ); + assert((mtctx->nextJobID & mtctx->jobIDMask) == (mtctx->doneJobID & mtctx->jobIDMask)); return 0; } @@ -1468,9 +1424,7 @@ public static unsafe partial class Methods mtctx->jobs[jobID].firstJob = mtctx->nextJobID == 0 ? 1U : 0U; mtctx->jobs[jobID].lastJob = (uint)endFrame; mtctx->jobs[jobID].frameChecksumNeeded = - mtctx->@params.fParams.checksumFlag != 0 - && endFrame != 0 - && mtctx->nextJobID > 0 + mtctx->@params.fParams.checksumFlag != 0 && endFrame != 0 && mtctx->nextJobID > 0 ? 1U : 0U; mtctx->jobs[jobID].dstFlushed = 0; @@ -1593,8 +1547,7 @@ public static unsafe partial class Methods { memcpy( (sbyte*)output->dst + output->pos, - (sbyte*)mtctx->jobs[wJobID].dstBuff.start - + mtctx->jobs[wJobID].dstFlushed, + (sbyte*)mtctx->jobs[wJobID].dstBuff.start + mtctx->jobs[wJobID].dstFlushed, (uint)toFlush ); } @@ -1694,11 +1647,9 @@ public static unsafe partial class Methods extDict.size = window.dictLimit - window.lowLimit; prefix.start = window.@base + window.dictLimit; prefix.size = (nuint)(window.nextSrc - (window.@base + window.dictLimit)); - return - ZSTDMT_isOverlapped(buffer, extDict) != 0 - || ZSTDMT_isOverlapped(buffer, prefix) != 0 - ? 1 - : 0; + return ZSTDMT_isOverlapped(buffer, extDict) != 0 || ZSTDMT_isOverlapped(buffer, prefix) != 0 + ? 1 + : 0; } private static void ZSTDMT_waitForLdmComplete(ZSTDMT_CCtx_s* mtctx, buffer_s buffer) @@ -1770,10 +1721,7 @@ public static unsafe partial class Methods * Otherwise, we will load as many bytes as possible and instruct the caller * to continue as normal. */ - private static SyncPoint findSynchronizationPoint( - ZSTDMT_CCtx_s* mtctx, - ZSTD_inBuffer_s input - ) + private static SyncPoint findSynchronizationPoint(ZSTDMT_CCtx_s* mtctx, ZSTD_inBuffer_s input) { byte* istart = (byte*)input.src + input.pos; ulong primePower = mtctx->rsync.primePower; @@ -1906,8 +1854,8 @@ public static unsafe partial class Methods { assert( mtctx->inBuff.filled == 0 - || mtctx->inBuff.filled == mtctx->targetSectionSize - || mtctx->@params.rsyncable != 0 + || mtctx->inBuff.filled == mtctx->targetSectionSize + || mtctx->@params.rsyncable != 0 ); endOp = ZSTD_EndDirective.ZSTD_e_flush; } diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/inBuff_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/inBuff_t.cs index df3642fa..1ea5fe48 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/inBuff_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/inBuff_t.cs @@ -9,4 +9,4 @@ public struct InBuff_t public Range prefix; public buffer_s buffer; public nuint filled; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmRollingHashState_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmRollingHashState_t.cs index c27abfca..73d11fd4 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmRollingHashState_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmRollingHashState_t.cs @@ -4,4 +4,4 @@ public struct ldmRollingHashState_t { public ulong rolling; public ulong stopMask; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmState_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmState_t.cs index 8ee9d9a7..5596880d 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmState_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/ldmState_t.cs @@ -15,11 +15,11 @@ public unsafe struct ldmState_t public _matchCandidates_e__FixedBuffer matchCandidates; #if NET8_0_OR_GREATER - [InlineArray(64)] - public unsafe struct _splitIndices_e__FixedBuffer - { - public nuint e0; - } + [InlineArray(64)] + public unsafe struct _splitIndices_e__FixedBuffer + { + public nuint e0; + } #else public unsafe struct _splitIndices_e__FixedBuffer @@ -92,11 +92,11 @@ public unsafe struct ldmState_t #endif #if NET8_0_OR_GREATER - [InlineArray(64)] - public unsafe struct _matchCandidates_e__FixedBuffer - { - public ldmMatchCandidate_t e0; - } + [InlineArray(64)] + public unsafe struct _matchCandidates_e__FixedBuffer + { + public ldmMatchCandidate_t e0; + } #else public unsafe struct _matchCandidates_e__FixedBuffer diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/offsetCount_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/offsetCount_t.cs index 6f24d4f6..9a5c8098 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/offsetCount_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/offsetCount_t.cs @@ -4,4 +4,4 @@ public struct offsetCount_t { public uint offset; public uint count; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/rankValCol_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/rankValCol_t.cs index ea52c69f..94eea418 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/rankValCol_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/rankValCol_t.cs @@ -3,4 +3,4 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public unsafe struct rankValCol_t { public fixed uint Body[13]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/repcodes_s.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/repcodes_s.cs index a9624f7c..f9b97bda 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/repcodes_s.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/repcodes_s.cs @@ -3,4 +3,4 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public unsafe struct repcodes_s { public fixed uint rep[3]; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/Unsafe/sortedSymbol_t.cs b/src/SharpCompress/Compressors/ZStandard/Unsafe/sortedSymbol_t.cs index f80373a1..acfe3dd9 100644 --- a/src/SharpCompress/Compressors/ZStandard/Unsafe/sortedSymbol_t.cs +++ b/src/SharpCompress/Compressors/ZStandard/Unsafe/sortedSymbol_t.cs @@ -3,4 +3,4 @@ namespace SharpCompress.Compressors.ZStandard.Unsafe; public struct sortedSymbol_t { public byte symbol; -} \ No newline at end of file +} diff --git a/src/SharpCompress/Compressors/ZStandard/UnsafeHelper.cs b/src/SharpCompress/Compressors/ZStandard/UnsafeHelper.cs index d2ea3575..b145099b 100644 --- a/src/SharpCompress/Compressors/ZStandard/UnsafeHelper.cs +++ b/src/SharpCompress/Compressors/ZStandard/UnsafeHelper.cs @@ -19,12 +19,12 @@ public static unsafe class UnsafeHelper #if NET6_0_OR_GREATER var ptr = NativeMemory.Alloc((nuint)size); #else - var ptr = (void*)Marshal.AllocHGlobal((nint)size); + var ptr = (void*)Marshal.AllocHGlobal((nint)size); #endif #if DEBUG return PoisonMemory(ptr, size); #else - return ptr; + return ptr; #endif } @@ -34,11 +34,11 @@ public static unsafe class UnsafeHelper #if NET6_0_OR_GREATER return NativeMemory.AllocZeroed((nuint)num, (nuint)size); #else - var total = num * size; - assert(total <= uint.MaxValue); - var destination = (void*)Marshal.AllocHGlobal((nint)total); - memset(destination, 0, (uint)total); - return destination; + var total = num * size; + assert(total <= uint.MaxValue); + var destination = (void*)Marshal.AllocHGlobal((nint)total); + memset(destination, 0, (uint)total); + return destination; #endif } @@ -56,7 +56,7 @@ public static unsafe class UnsafeHelper #if NET6_0_OR_GREATER NativeMemory.Free(ptr); #else - Marshal.FreeHGlobal((IntPtr)ptr); + Marshal.FreeHGlobal((IntPtr)ptr); #endif } @@ -66,23 +66,19 @@ public static unsafe class UnsafeHelper { var size = (uint)(sizeof(T) * array.Length); #if NET9_0_OR_GREATER - // This function is used to allocate memory for static data blocks. - // We have to use AllocateTypeAssociatedMemory and link the memory's - // lifetime to this assembly, in order to prevent memory leaks when - // loading the assembly in an unloadable AssemblyLoadContext. - // While introduced in .NET 5, we call this only in .NET 9+, because - // it's not implemented in the Mono runtime until then. - var destination = (T*) - RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UnsafeHelper), (int)size); + // This function is used to allocate memory for static data blocks. + // We have to use AllocateTypeAssociatedMemory and link the memory's + // lifetime to this assembly, in order to prevent memory leaks when + // loading the assembly in an unloadable AssemblyLoadContext. + // While introduced in .NET 5, we call this only in .NET 9+, because + // it's not implemented in the Mono runtime until then. + var destination = (T*) + RuntimeHelpers.AllocateTypeAssociatedMemory(typeof(UnsafeHelper), (int)size); #else var destination = (T*)malloc(size); #endif fixed (void* source = &array[0]) - System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned( - destination, - source, - size - ); + System.Runtime.CompilerServices.Unsafe.CopyBlockUnaligned(destination, source, size); return destination; } diff --git a/src/SharpCompress/Factories/ArcFactory.cs b/src/SharpCompress/Factories/ArcFactory.cs index 040263e2..ea0617ee 100644 --- a/src/SharpCompress/Factories/ArcFactory.cs +++ b/src/SharpCompress/Factories/ArcFactory.cs @@ -42,4 +42,4 @@ public class ArcFactory : Factory, IReaderFactory public IReader OpenReader(Stream stream, ReaderOptions? options) => ArcReader.Open(stream, options); -} \ No newline at end of file +} diff --git a/src/SharpCompress/IO/IStreamStack.cs b/src/SharpCompress/IO/IStreamStack.cs index c572de1e..1c7582ad 100644 --- a/src/SharpCompress/IO/IStreamStack.cs +++ b/src/SharpCompress/IO/IStreamStack.cs @@ -42,10 +42,10 @@ public interface IStreamStack void SetPosition(long position); #if DEBUG_STREAMS - /// - /// Gets or sets the unique instance identifier for debugging purposes. - /// - long InstanceId { get; set; } + /// + /// Gets or sets the unique instance identifier for debugging purposes. + /// + long InstanceId { get; set; } #endif } @@ -240,124 +240,118 @@ internal static class StackStreamExtensions } #if DEBUG_STREAMS - private static long _instanceCounter = 0; + private static long _instanceCounter = 0; - private static string cleansePos(long pos) - { - if (pos < 0) - return ""; - return "Px" + pos.ToString("x"); - } + private static string cleansePos(long pos) + { + if (pos < 0) + return ""; + return "Px" + pos.ToString("x"); + } - /// - /// Gets or creates a unique instance ID for the stream stack for debugging purposes. - /// - /// The stream stack. - /// Reference to the instance ID field. - /// Whether this is being called during construction. - /// The instance ID. - public static long GetInstanceId( - this IStreamStack stream, - ref long instanceId, - bool construct - ) - { - if (instanceId == 0) //will not be equal to 0 when inherited IStackStream types are being used - instanceId = System.Threading.Interlocked.Increment(ref _instanceCounter); - return instanceId; - } + /// + /// Gets or creates a unique instance ID for the stream stack for debugging purposes. + /// + /// The stream stack. + /// Reference to the instance ID field. + /// Whether this is being called during construction. + /// The instance ID. + public static long GetInstanceId(this IStreamStack stream, ref long instanceId, bool construct) + { + if (instanceId == 0) //will not be equal to 0 when inherited IStackStream types are being used + instanceId = System.Threading.Interlocked.Increment(ref _instanceCounter); + return instanceId; + } - /// - /// Writes a debug message for stream construction. - /// - /// The stream stack. - /// The type being constructed. - public static void DebugConstruct(this IStreamStack stream, Type constructing) - { - long id = stream.InstanceId; - stream.InstanceId = GetInstanceId(stream, ref id, true); - var frame = (new StackTrace()).GetFrame(3); - string parentInfo = - frame != null - ? $"{frame.GetMethod()?.DeclaringType?.Name}.{frame.GetMethod()?.Name}()" - : "Unknown"; - if (constructing.FullName == stream.GetType().FullName) //don't debug base IStackStream types - Debug.WriteLine( - $"{GetStreamStackString(stream, true)} : Constructed by [{parentInfo}]" - ); - } + /// + /// Writes a debug message for stream construction. + /// + /// The stream stack. + /// The type being constructed. + public static void DebugConstruct(this IStreamStack stream, Type constructing) + { + long id = stream.InstanceId; + stream.InstanceId = GetInstanceId(stream, ref id, true); + var frame = (new StackTrace()).GetFrame(3); + string parentInfo = + frame != null + ? $"{frame.GetMethod()?.DeclaringType?.Name}.{frame.GetMethod()?.Name}()" + : "Unknown"; + if (constructing.FullName == stream.GetType().FullName) //don't debug base IStackStream types + Debug.WriteLine($"{GetStreamStackString(stream, true)} : Constructed by [{parentInfo}]"); + } - /// - /// Writes a debug message for stream disposal. - /// - /// The stream stack. - /// The type being disposed. - public static void DebugDispose(this IStreamStack stream, Type constructing) - { - var frame = (new StackTrace()).GetFrame(3); - string parentInfo = - frame != null - ? $"{frame.GetMethod()?.DeclaringType?.Name}.{frame.GetMethod()?.Name}()" - : "Unknown"; - if (constructing.FullName == stream.GetType().FullName) //don't debug base IStackStream types - Debug.WriteLine($"{GetStreamStackString(stream, false)} : Disposed by [{parentInfo}]"); - } + /// + /// Writes a debug message for stream disposal. + /// + /// The stream stack. + /// The type being disposed. + public static void DebugDispose(this IStreamStack stream, Type constructing) + { + var frame = (new StackTrace()).GetFrame(3); + string parentInfo = + frame != null + ? $"{frame.GetMethod()?.DeclaringType?.Name}.{frame.GetMethod()?.Name}()" + : "Unknown"; + if (constructing.FullName == stream.GetType().FullName) //don't debug base IStackStream types + Debug.WriteLine($"{GetStreamStackString(stream, false)} : Disposed by [{parentInfo}]"); + } - /// - /// Writes a debug trace message for the stream. - /// - /// The stream stack. - /// The debug message to write. - public static void DebugTrace(this IStreamStack stream, string message) - { - Debug.WriteLine( - $"{GetStreamStackString(stream, false)} : [{stream.GetType().Name}]{message}" - ); - } + /// + /// Writes a debug trace message for the stream. + /// + /// The stream stack. + /// The debug message to write. + public static void DebugTrace(this IStreamStack stream, string message) + { + Debug.WriteLine( + $"{GetStreamStackString(stream, false)} : [{stream.GetType().Name}]{message}" + ); + } - /// - /// Returns the full stream chain as a string, including instance IDs and positions. - /// - /// The stream stack to represent. - /// Whether this is being called during construction. - /// A string representation of the entire stream stack. - public static string GetStreamStackString(this IStreamStack stream, bool construct) + /// + /// Returns the full stream chain as a string, including instance IDs and positions. + /// + /// The stream stack to represent. + /// Whether this is being called during construction. + /// A string representation of the entire stream stack. + public static string GetStreamStackString(this IStreamStack stream, bool construct) + { + var sb = new StringBuilder(); + Stream? current = stream as Stream; + while (current != null) { - var sb = new StringBuilder(); - Stream? current = stream as Stream; - while (current != null) + IStreamStack? sStack = current as IStreamStack; + string id = sStack != null ? "#" + sStack.InstanceId.ToString() : ""; + string buffSize = sStack != null ? "Bx" + sStack.BufferSize.ToString("x") : ""; + string defBuffSize = + sStack != null ? "Dx" + sStack.DefaultBufferSize.ToString("x") : ""; + + if (sb.Length > 0) + sb.Insert(0, "/"); + try { - IStreamStack? sStack = current as IStreamStack; - string id = sStack != null ? "#" + sStack.InstanceId.ToString() : ""; - string buffSize = sStack != null ? "Bx" + sStack.BufferSize.ToString("x") : ""; - string defBuffSize = - sStack != null ? "Dx" + sStack.DefaultBufferSize.ToString("x") : ""; - - if (sb.Length > 0) - sb.Insert(0, "/"); - try - { + sb.Insert( + 0, + $"{current.GetType().Name}{id}[{cleansePos(current.Position)}:{buffSize}:{defBuffSize}]" + ); + } + catch + { + if (current is SharpCompressStream scs) sb.Insert( 0, - $"{current.GetType().Name}{id}[{cleansePos(current.Position)}:{buffSize}:{defBuffSize}]" + $"{current.GetType().Name}{id}[{cleansePos(scs.InternalPosition)}:{buffSize}:{defBuffSize}]" ); - } - catch - { - if (current is SharpCompressStream scs) - sb.Insert( - 0, - $"{current.GetType().Name}{id}[{cleansePos(scs.InternalPosition)}:{buffSize}:{defBuffSize}]" - ); - else - sb.Insert(0, $"{current.GetType().Name}{id}[:{buffSize}]"); - } - if (sStack != null) - current = sStack.BaseStream(); //current may not be a IStreamStack, allow one more loop else - break; + sb.Insert(0, $"{current.GetType().Name}{id}[:{buffSize}]"); } - return sb.ToString(); + if (sStack != null) + current = sStack.BaseStream(); //current may not be a IStreamStack, allow one more loop + else + break; } + return sb.ToString(); + } #endif } diff --git a/src/SharpCompress/Readers/Arc/ArcReader.cs b/src/SharpCompress/Readers/Arc/ArcReader.cs index 6ad6a382..760f6345 100644 --- a/src/SharpCompress/Readers/Arc/ArcReader.cs +++ b/src/SharpCompress/Readers/Arc/ArcReader.cs @@ -37,4 +37,4 @@ public class ArcReader : AbstractReader yield return new ArcEntry(new ArcFilePart(header, stream)); } } -} \ No newline at end of file +}