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
+18
View File
@@ -636,6 +636,24 @@ public static class CollectionExtensions
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)]
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);
_buckets = new T?[minimumCapacity];
Array.Fill(_buckets, _defaultValue);
_buckets.Fill(_defaultValue);
_tails = new((uint)minimumCapacity);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1;
@@ -447,7 +447,7 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
_tails = new((uint)_buckets.Length << 1);
_buckets = new T?[_buckets.Length << 1];
Array.Fill(_buckets, _defaultValue);
_buckets.Fill(_defaultValue);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1;
@@ -618,7 +618,7 @@ public class FishSet<T> : ISet<T>, IReadOnlyCollection<T>, ICollection
if (_buckets is null)
Initialize();
Array.Fill(_buckets, _defaultValue);
_buckets.Fill(_defaultValue);
_tails.Reset();
_count = 0;
+3 -3
View File
@@ -266,7 +266,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
// Mathf.NextPowerOfTwo(minimumCapacity);
_buckets = new Entry[minimumCapacity];
Array.Fill(_buckets, _defaultEntry);
_buckets.Fill(_defaultEntry);
_tails = new((uint)minimumCapacity);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)_buckets.Length);
_wrapAroundMask = _buckets.Length - 1;
@@ -657,7 +657,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
_tails = new((uint)newSize);
_buckets = new Entry[newSize];
Array.Fill(_buckets, _defaultEntry);
_buckets.Fill(_defaultEntry);
_bucketBitShift = 32 - FishMath.TrailingZeroCount((uint)newSize);
_wrapAroundMask = _buckets.Length - 1;
@@ -1298,7 +1298,7 @@ public class FishTable<TKey, TValue> : IDictionary<TKey, TValue>, IDictionary, I
if (_buckets is null)
Initialize();
Array.Fill(_buckets, _defaultEntry);
_buckets.Fill(_defaultEntry);
_tails.Reset();
_count = 0;
+2 -2
View File
@@ -29,11 +29,11 @@ namespace FisheryLib;
[PublicAPI]
public static class FisheryLib
{
public const decimal VERSION = 0.51M;
public const decimal VERSION = 0.511M;
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()
// {