Skip to content

Commit

Permalink
Converted some object initializations to constructors (.NET Native wo…
Browse files Browse the repository at this point in the history
…rkaround)
  • Loading branch information
oleg-st committed Oct 17, 2023
1 parent 3767e20 commit 3b27163
Show file tree
Hide file tree
Showing 12 changed files with 49 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/Clevels.cs

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/ZstdSharp/Unsafe/FASTCOVER_accel_t.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,10 @@ public struct FASTCOVER_accel_t
public uint finalize;
/* Number of dmer skipped between each dmer counted in computeFrequency */
public uint skip;
public FASTCOVER_accel_t(uint finalize = default, uint skip = default)
{
this.finalize = finalize;
this.skip = skip;
}
}
}
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/Fastcover.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ private static nuint FASTCOVER_hashPtrToIndex(void* p, uint f, uint d)
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
***************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/HufDecompress.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1862,7 +1862,7 @@ private static nuint HUF_decompress4X2_DCtx_wksp(uint* dctx, void* dst, nuint ds
return HUF_decompress4X2_usingDTable_internal(dst, dstSize, ip, cSrcSize, dctx, flags);
}

private static readonly algo_time_t[][] algoTime = new algo_time_t[16][] { new algo_time_t[2] { new algo_time_t { tableTime = 0, decode256Time = 0 }, new algo_time_t { tableTime = 1, decode256Time = 1 } }, new algo_time_t[2] { new algo_time_t { tableTime = 0, decode256Time = 0 }, new algo_time_t { tableTime = 1, decode256Time = 1 } }, new algo_time_t[2] { new algo_time_t { tableTime = 150, decode256Time = 216 }, new algo_time_t { tableTime = 381, decode256Time = 119 } }, new algo_time_t[2] { new algo_time_t { tableTime = 170, decode256Time = 205 }, new algo_time_t { tableTime = 514, decode256Time = 112 } }, new algo_time_t[2] { new algo_time_t { tableTime = 177, decode256Time = 199 }, new algo_time_t { tableTime = 539, decode256Time = 110 } }, new algo_time_t[2] { new algo_time_t { tableTime = 197, decode256Time = 194 }, new algo_time_t { tableTime = 644, decode256Time = 107 } }, new algo_time_t[2] { new algo_time_t { tableTime = 221, decode256Time = 192 }, new algo_time_t { tableTime = 735, decode256Time = 107 } }, new algo_time_t[2] { new algo_time_t { tableTime = 256, decode256Time = 189 }, new algo_time_t { tableTime = 881, decode256Time = 106 } }, new algo_time_t[2] { new algo_time_t { tableTime = 359, decode256Time = 188 }, new algo_time_t { tableTime = 1167, decode256Time = 109 } }, new algo_time_t[2] { new algo_time_t { tableTime = 582, decode256Time = 187 }, new algo_time_t { tableTime = 1570, decode256Time = 114 } }, new algo_time_t[2] { new algo_time_t { tableTime = 688, decode256Time = 187 }, new algo_time_t { tableTime = 1712, decode256Time = 122 } }, new algo_time_t[2] { new algo_time_t { tableTime = 825, decode256Time = 186 }, new algo_time_t { tableTime = 1965, decode256Time = 136 } }, new algo_time_t[2] { new algo_time_t { tableTime = 976, decode256Time = 185 }, new algo_time_t { tableTime = 2131, decode256Time = 150 } }, new algo_time_t[2] { new algo_time_t { tableTime = 1180, decode256Time = 186 }, new algo_time_t { tableTime = 2070, decode256Time = 175 } }, new algo_time_t[2] { new algo_time_t { tableTime = 1377, decode256Time = 185 }, new algo_time_t { tableTime = 1731, decode256Time = 202 } }, new algo_time_t[2] { new algo_time_t { tableTime = 1412, decode256Time = 185 }, new algo_time_t { tableTime = 1695, decode256Time = 202 } } };
private static readonly algo_time_t[][] algoTime = new algo_time_t[16][] { new algo_time_t[2] { new algo_time_t(tableTime: 0, decode256Time: 0), new algo_time_t(tableTime: 1, decode256Time: 1) }, new algo_time_t[2] { new algo_time_t(tableTime: 0, decode256Time: 0), new algo_time_t(tableTime: 1, decode256Time: 1) }, new algo_time_t[2] { new algo_time_t(tableTime: 150, decode256Time: 216), new algo_time_t(tableTime: 381, decode256Time: 119) }, new algo_time_t[2] { new algo_time_t(tableTime: 170, decode256Time: 205), new algo_time_t(tableTime: 514, decode256Time: 112) }, new algo_time_t[2] { new algo_time_t(tableTime: 177, decode256Time: 199), new algo_time_t(tableTime: 539, decode256Time: 110) }, new algo_time_t[2] { new algo_time_t(tableTime: 197, decode256Time: 194), new algo_time_t(tableTime: 644, decode256Time: 107) }, new algo_time_t[2] { new algo_time_t(tableTime: 221, decode256Time: 192), new algo_time_t(tableTime: 735, decode256Time: 107) }, new algo_time_t[2] { new algo_time_t(tableTime: 256, decode256Time: 189), new algo_time_t(tableTime: 881, decode256Time: 106) }, new algo_time_t[2] { new algo_time_t(tableTime: 359, decode256Time: 188), new algo_time_t(tableTime: 1167, decode256Time: 109) }, new algo_time_t[2] { new algo_time_t(tableTime: 582, decode256Time: 187), new algo_time_t(tableTime: 1570, decode256Time: 114) }, new algo_time_t[2] { new algo_time_t(tableTime: 688, decode256Time: 187), new algo_time_t(tableTime: 1712, decode256Time: 122) }, new algo_time_t[2] { new algo_time_t(tableTime: 825, decode256Time: 186), new algo_time_t(tableTime: 1965, decode256Time: 136) }, new algo_time_t[2] { new algo_time_t(tableTime: 976, decode256Time: 185), new algo_time_t(tableTime: 2131, decode256Time: 150) }, new algo_time_t[2] { new algo_time_t(tableTime: 1180, decode256Time: 186), new algo_time_t(tableTime: 2070, decode256Time: 175) }, new algo_time_t[2] { new algo_time_t(tableTime: 1377, decode256Time: 185), new algo_time_t(tableTime: 1731, decode256Time: 202) }, new algo_time_t[2] { new algo_time_t(tableTime: 1412, decode256Time: 185), new algo_time_t(tableTime: 1695, decode256Time: 202) } };
/** HUF_selectDecoder() :
* Tells which decoder is likely to decode faster,
* based on a set of pre-computed metrics.
Expand Down
10 changes: 10 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_compressionParameters.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@ public struct ZSTD_compressionParameters
public uint targetLength;
/**< see ZSTD_strategy definition above */
public ZSTD_strategy strategy;
public ZSTD_compressionParameters(uint windowLog = default, uint chainLog = default, uint hashLog = default, uint searchLog = default, uint minMatch = default, uint targetLength = default, ZSTD_strategy strategy = default)
{
this.windowLog = windowLog;
this.chainLog = chainLog;
this.hashLog = hashLog;
this.searchLog = searchLog;
this.minMatch = minMatch;
this.targetLength = targetLength;
this.strategy = strategy;
}
}
}
6 changes: 6 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_customMem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ public unsafe struct ZSTD_customMem
public void* customAlloc;
public void* customFree;
public void* opaque;
public ZSTD_customMem(void* customAlloc = default, void* customFree = default, void* opaque = default)
{
this.customAlloc = customAlloc;
this.customFree = customFree;
this.opaque = opaque;
}
}
}
7 changes: 7 additions & 0 deletions src/ZstdSharp/Unsafe/ZSTD_seqSymbol.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,12 @@ public struct ZSTD_seqSymbol
public byte nbAdditionalBits;
public byte nbBits;
public uint baseValue;
public ZSTD_seqSymbol(ushort nextState = default, byte nbAdditionalBits = default, byte nbBits = default, uint baseValue = default)
{
this.nextState = nextState;
this.nbAdditionalBits = nbAdditionalBits;
this.nbBits = nbBits;
this.baseValue = baseValue;
}
}
}
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/Zstd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ namespace ZstdSharp.Unsafe
{
public static unsafe partial class Methods
{
private static readonly ZSTD_customMem ZSTD_defaultCMem = new ZSTD_customMem { customAlloc = null, customFree = null, opaque = null };
private static readonly ZSTD_customMem ZSTD_defaultCMem = new ZSTD_customMem(customAlloc: null, customFree: null, opaque: null);
}
}
2 changes: 1 addition & 1 deletion src/ZstdSharp/Unsafe/ZstdCompressInternal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace ZstdSharp.Unsafe
{
public static unsafe partial class Methods
{
private static readonly rawSeqStore_t kNullRawSeqStore = new rawSeqStore_t { seq = null, pos = 0, posInSequence = 0, size = 0, capacity = 0 };
private static readonly rawSeqStore_t kNullRawSeqStore = new rawSeqStore_t(seq: null, pos: 0, posInSequence: 0, size: 0, capacity: 0);
#if NET7_0_OR_GREATER
private static ReadOnlySpan<byte> 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));
Expand Down
Loading

1 comment on commit 3b27163

@oleg-st
Copy link
Owner Author

@oleg-st oleg-st commented on 3b27163 Oct 18, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea is taken from
StackExchange/StackExchange.Redis#2212 (comment)

Object initializers also produce "ldloca.s" IL instruction in static initialization.

Please sign in to comment.