Fixed ArrayTypeMismatchException thrown on FishSets and Tables with certain reference type default values

This commit is contained in:
bbradson
2024-04-15 05:26:49 +02:00
parent 8d23bff6ba
commit 040a756d2e
12 changed files with 26 additions and 8 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+18
View File
@@ -636,6 +636,24 @@ public static class CollectionExtensions
return destination; return destination;
} }
public static unsafe void Fill<T>(this T[] array, T value)
{
Guard.IsNotNull(array);
if (array.Length == 0)
return;
fixed (T* startAddress = &array[0])
{
var i = array.Length - 1;
do
{
startAddress[i] = value;
}
while (--i >= 0);
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRangeFast<T>(this List<T> list, T[] range) public static void AddRangeFast<T>(this List<T> list, T[] range)
{ {
+3 -3
View File
@@ -157,7 +157,7 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
// Mathf.NextPowerOfTwo(minimumCapacity); // Mathf.NextPowerOfTwo(minimumCapacity);
_buckets = new T?[minimumCapacity]; _buckets = new T?[minimumCapacity];
Array.Fill(_buckets, _defaultValue); _buckets.Fill(_defaultValue);
_tails = new((uint)minimumCapacity); _tails = new((uint)minimumCapacity);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length); _bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1; _wrapAroundMask = _buckets.Length - 1;
@@ -447,7 +447,7 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
_tails = new((uint)_buckets.Length << 1); _tails = new((uint)_buckets.Length << 1);
_buckets = new T?[_buckets.Length << 1]; _buckets = new T?[_buckets.Length << 1];
Array.Fill(_buckets, _defaultValue); _buckets.Fill(_defaultValue);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length); _bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1; _wrapAroundMask = _buckets.Length - 1;
@@ -618,7 +618,7 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
if (_buckets is null) if (_buckets is null)
Initialize(); Initialize();
Array.Fill(_buckets, _defaultValue); _buckets.Fill(_defaultValue);
_tails.Reset(); _tails.Reset();
_count = 0; _count = 0;
+3 -3
View File
@@ -266,7 +266,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
// Mathf.NextPowerOfTwo(minimumCapacity); // Mathf.NextPowerOfTwo(minimumCapacity);
_buckets = new Entry[minimumCapacity]; _buckets = new Entry[minimumCapacity];
Array.Fill(_buckets, _defaultEntry); _buckets.Fill(_defaultEntry);
_tails = new((uint)minimumCapacity); _tails = new((uint)minimumCapacity);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length); _bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1; _wrapAroundMask = _buckets.Length - 1;
@@ -657,7 +657,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
_tails = new((uint)newSize); _tails = new((uint)newSize);
_buckets = new Entry[newSize]; _buckets = new Entry[newSize];
Array.Fill(_buckets, _defaultEntry); _buckets.Fill(_defaultEntry);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)newSize); _bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)newSize);
_wrapAroundMask = _buckets.Length - 1; _wrapAroundMask = _buckets.Length - 1;
@@ -1298,7 +1298,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
if (_buckets is null) if (_buckets is null)
Initialize(); Initialize();
Array.Fill(_buckets, _defaultEntry); _buckets.Fill(_defaultEntry);
_tails.Reset(); _tails.Reset();
_count = 0; _count = 0;
+2 -2
View File
@@ -29,11 +29,11 @@ namespace FisheryLib;
[PublicAPI] [PublicAPI]
public static class FisheryLib public static class FisheryLib
{ {
public const decimal VERSION = 0.51M; public const decimal VERSION = 0.511M;
public static decimal CurrentlyLoadedVersion { get; } = VERSION; public static decimal CurrentlyLoadedVersion { get; } = VERSION;
public const string VERSION_STRING = "0.5.1.0"; public const string VERSION_STRING = "0.5.1.1";
// public static string GetVersion() // public static string GetVersion()
// { // {