more default value related fixes for FishSet and FishTable

This commit is contained in:
bbradson
2024-04-15 07:27:58 +02:00
parent 040a756d2e
commit 5656c3e80b
12 changed files with 58 additions and 23 deletions
+17 -10
View File
@@ -636,24 +636,31 @@ public static class CollectionExtensions
return destination;
}
public static unsafe void Fill<T>(this T[] array, T value)
public static void Fill<T>(this T[] array, T value)
{
Guard.IsNotNull(array);
var i = array.Length - 1;
if (array.Length == 0)
if (i < 0)
return;
fixed (T* startAddress = &array[0])
do
{
var i = array.Length - 1;
do
{
startAddress[i] = value;
}
while (--i >= 0);
array.UnsafeStore(i, value);
}
while (--i >= 0);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static T UnsafeLoad<T>(this T[] array, int index) => Array.UnsafeLoad(array, index);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UnsafeStore<T>(this T[] array, int index, T value) => Array.UnsafeStore(array, index, value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static TTo UnsafeCast<TFrom, TTo>(this TFrom obj) => Array.UnsafeMov<TFrom, TTo>(obj);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void AddRangeFast<T>(this List<T> list, T[] range)
{