Refactor multiline variable declarations
This commit is contained in:
Родитель
51c7a67c20
Коммит
6afdd81742
|
@ -132,9 +132,8 @@ public static class ArrayExtensions
|
|||
|
||||
_ = builder.Append('[');
|
||||
|
||||
int
|
||||
height = array.GetLength(0),
|
||||
width = array.GetLength(1);
|
||||
int height = array.GetLength(0);
|
||||
int width = array.GetLength(1);
|
||||
|
||||
for (int i = 0; i < height; i++)
|
||||
{
|
||||
|
|
|
@ -47,9 +47,8 @@ public static class ValueTypeExtensions
|
|||
public static unsafe string ToHexString<T>(this T value)
|
||||
where T : unmanaged
|
||||
{
|
||||
int
|
||||
sizeOfT = Unsafe.SizeOf<T>(),
|
||||
bufferSize = (2 * sizeOfT) + 2;
|
||||
int sizeOfT = Unsafe.SizeOf<T>();
|
||||
int bufferSize = (2 * sizeOfT) + 2;
|
||||
char* p = stackalloc char[bufferSize];
|
||||
|
||||
p[0] = '0';
|
||||
|
@ -60,9 +59,8 @@ public static class ValueTypeExtensions
|
|||
for (int i = 0, j = bufferSize - 2; i < sizeOfT; i++, j -= 2)
|
||||
{
|
||||
byte b = ((byte*)&value)[i];
|
||||
int
|
||||
low = b & 0x0F,
|
||||
high = (b & 0xF0) >> 4;
|
||||
int low = b & 0x0F;
|
||||
int high = (b & 0xF0) >> 4;
|
||||
|
||||
p[j + 1] = (char)Unsafe.Add(ref rh, low);
|
||||
p[j] = (char)Unsafe.Add(ref rh, high);
|
||||
|
|
|
@ -75,10 +75,9 @@ internal sealed class ArrayMemoryManager<TFrom, TTo> : MemoryManager<TTo>, IMemo
|
|||
ThrowArgumentOutOfRangeExceptionForInvalidIndex();
|
||||
}
|
||||
|
||||
int
|
||||
bytePrefix = this.offset * Unsafe.SizeOf<TFrom>(),
|
||||
byteSuffix = elementIndex * Unsafe.SizeOf<TTo>(),
|
||||
byteOffset = bytePrefix + byteSuffix;
|
||||
int bytePrefix = this.offset * Unsafe.SizeOf<TFrom>();
|
||||
int byteSuffix = elementIndex * Unsafe.SizeOf<TTo>();
|
||||
int byteOffset = bytePrefix + byteSuffix;
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(this.array, GCHandleType.Pinned);
|
||||
|
||||
|
@ -107,9 +106,8 @@ internal sealed class ArrayMemoryManager<TFrom, TTo> : MemoryManager<TTo>, IMemo
|
|||
// We need to calculate the right offset and length of the new Memory<T>. The local offset
|
||||
// is the original offset into the wrapped TFrom[] array, while the input offset is the one
|
||||
// with respect to TTo items in the Memory<TTo> instance that is currently being cast.
|
||||
int
|
||||
absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, TFrom>(offset),
|
||||
absoluteLength = RuntimeHelpers.ConvertLength<TTo, TFrom>(length);
|
||||
int absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, TFrom>(offset);
|
||||
int absoluteLength = RuntimeHelpers.ConvertLength<TTo, TFrom>(length);
|
||||
|
||||
// We have a special handling in cases where the user is circling back to the original type
|
||||
// of the wrapped array. In this case we can just return a memory wrapping that array directly,
|
||||
|
|
|
@ -64,15 +64,13 @@ internal sealed class ProxyMemoryManager<TFrom, TTo> : MemoryManager<TTo>, IMemo
|
|||
ThrowArgumentExceptionForInvalidIndex();
|
||||
}
|
||||
|
||||
int
|
||||
bytePrefix = this.offset * Unsafe.SizeOf<TFrom>(),
|
||||
byteSuffix = elementIndex * Unsafe.SizeOf<TTo>(),
|
||||
byteOffset = bytePrefix + byteSuffix;
|
||||
int bytePrefix = this.offset * Unsafe.SizeOf<TFrom>();
|
||||
int byteSuffix = elementIndex * Unsafe.SizeOf<TTo>();
|
||||
int byteOffset = bytePrefix + byteSuffix;
|
||||
|
||||
#if NETSTANDARD1_4
|
||||
int
|
||||
shiftedOffset = byteOffset / Unsafe.SizeOf<TFrom>(),
|
||||
remainder = byteOffset - (shiftedOffset * Unsafe.SizeOf<TFrom>());
|
||||
int shiftedOffset = byteOffset / Unsafe.SizeOf<TFrom>();
|
||||
int remainder = byteOffset - (shiftedOffset * Unsafe.SizeOf<TFrom>());
|
||||
#else
|
||||
int shiftedOffset = Math.DivRem(byteOffset, Unsafe.SizeOf<TFrom>(), out int remainder);
|
||||
#endif
|
||||
|
@ -102,9 +100,8 @@ internal sealed class ProxyMemoryManager<TFrom, TTo> : MemoryManager<TTo>, IMemo
|
|||
where T : unmanaged
|
||||
{
|
||||
// Like in the other memory manager, calculate the absolute offset and length
|
||||
int
|
||||
absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, TFrom>(offset),
|
||||
absoluteLength = RuntimeHelpers.ConvertLength<TTo, TFrom>(length);
|
||||
int absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, TFrom>(offset);
|
||||
int absoluteLength = RuntimeHelpers.ConvertLength<TTo, TFrom>(length);
|
||||
|
||||
// Skip one indirection level and slice the original memory manager, if possible
|
||||
if (typeof(T) == typeof(TFrom))
|
||||
|
|
|
@ -71,10 +71,9 @@ internal sealed class StringMemoryManager<TTo> : MemoryManager<TTo>, IMemoryMana
|
|||
ThrowArgumentOutOfRangeExceptionForInvalidIndex();
|
||||
}
|
||||
|
||||
int
|
||||
bytePrefix = this.offset * Unsafe.SizeOf<char>(),
|
||||
byteSuffix = elementIndex * Unsafe.SizeOf<TTo>(),
|
||||
byteOffset = bytePrefix + byteSuffix;
|
||||
int bytePrefix = this.offset * Unsafe.SizeOf<char>();
|
||||
int byteSuffix = elementIndex * Unsafe.SizeOf<TTo>();
|
||||
int byteOffset = bytePrefix + byteSuffix;
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(this.text, GCHandleType.Pinned);
|
||||
|
||||
|
@ -100,9 +99,8 @@ internal sealed class StringMemoryManager<TTo> : MemoryManager<TTo>, IMemoryMana
|
|||
public Memory<T> GetMemory<T>(int offset, int length)
|
||||
where T : unmanaged
|
||||
{
|
||||
int
|
||||
absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, char>(offset),
|
||||
absoluteLength = RuntimeHelpers.ConvertLength<TTo, char>(length);
|
||||
int absoluteOffset = this.offset + RuntimeHelpers.ConvertLength<TTo, char>(offset);
|
||||
int absoluteLength = RuntimeHelpers.ConvertLength<TTo, char>(length);
|
||||
|
||||
if (typeof(T) == typeof(char))
|
||||
{
|
||||
|
|
|
@ -70,9 +70,8 @@ public sealed class StringPool
|
|||
// Calculates the rounded up factors for a specific size/factor pair
|
||||
static void FindFactors(int size, int factor, out int x, out int y)
|
||||
{
|
||||
double
|
||||
a = Math.Sqrt((double)size / factor),
|
||||
b = factor * a;
|
||||
double a = Math.Sqrt((double)size / factor);
|
||||
double b = factor * a;
|
||||
|
||||
x = BitOperations.RoundUpPowerOfTwo((int)a);
|
||||
y = BitOperations.RoundUpPowerOfTwo((int)b);
|
||||
|
@ -91,10 +90,9 @@ public sealed class StringPool
|
|||
FindFactors(minimumSize, 3, out int x3, out int y3);
|
||||
FindFactors(minimumSize, 4, out int x4, out int y4);
|
||||
|
||||
int
|
||||
p2 = x2 * y2,
|
||||
p3 = x3 * y3,
|
||||
p4 = x4 * y4;
|
||||
int p2 = x2 * y2;
|
||||
int p3 = x3 * y3;
|
||||
int p4 = x4 * y4;
|
||||
|
||||
if (p3 < p2)
|
||||
{
|
||||
|
@ -152,9 +150,8 @@ public sealed class StringPool
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
hashcode = GetHashCode(value.AsSpan()),
|
||||
bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
int hashcode = GetHashCode(value.AsSpan());
|
||||
int bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
|
||||
ref FixedSizePriorityMap map = ref this.maps.DangerousGetReferenceAt(bucketIndex);
|
||||
|
||||
|
@ -176,9 +173,8 @@ public sealed class StringPool
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
int
|
||||
hashcode = GetHashCode(value.AsSpan()),
|
||||
bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
int hashcode = GetHashCode(value.AsSpan());
|
||||
int bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
|
||||
ref FixedSizePriorityMap map = ref this.maps.DangerousGetReferenceAt(bucketIndex);
|
||||
|
||||
|
@ -200,9 +196,8 @@ public sealed class StringPool
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
int
|
||||
hashcode = GetHashCode(span),
|
||||
bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
int hashcode = GetHashCode(span);
|
||||
int bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
|
||||
ref FixedSizePriorityMap map = ref this.maps.DangerousGetReferenceAt(bucketIndex);
|
||||
|
||||
|
@ -253,9 +248,8 @@ public sealed class StringPool
|
|||
return true;
|
||||
}
|
||||
|
||||
int
|
||||
hashcode = GetHashCode(span),
|
||||
bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
int hashcode = GetHashCode(span);
|
||||
int bucketIndex = hashcode & (this.numberOfMaps - 1);
|
||||
|
||||
ref FixedSizePriorityMap map = ref this.maps.DangerousGetReferenceAt(bucketIndex);
|
||||
|
||||
|
@ -499,9 +493,8 @@ public sealed class StringPool
|
|||
{
|
||||
ref MapEntry mapEntriesRef = ref this.mapEntries.DangerousGetReference();
|
||||
ref MapEntry entry = ref Unsafe.NullRef<MapEntry>();
|
||||
int
|
||||
length = this.buckets.Length,
|
||||
bucketIndex = hashcode & (length - 1);
|
||||
int length = this.buckets.Length;
|
||||
int bucketIndex = hashcode & (length - 1);
|
||||
|
||||
for (int i = this.buckets.DangerousGetReferenceAt(bucketIndex) - 1;
|
||||
(uint)i < (uint)length;
|
||||
|
@ -590,10 +583,9 @@ public sealed class StringPool
|
|||
private void Remove(int hashcode, int mapIndex)
|
||||
{
|
||||
ref MapEntry mapEntriesRef = ref this.mapEntries.DangerousGetReference();
|
||||
int
|
||||
bucketIndex = hashcode & (this.buckets.Length - 1),
|
||||
entryIndex = this.buckets.DangerousGetReferenceAt(bucketIndex) - 1,
|
||||
lastIndex = EndOfList;
|
||||
int bucketIndex = hashcode & (this.buckets.Length - 1);
|
||||
int entryIndex = this.buckets.DangerousGetReferenceAt(bucketIndex) - 1;
|
||||
int lastIndex = EndOfList;
|
||||
|
||||
// We can just have an undefined loop, as the input
|
||||
// value we're looking for is guaranteed to be present
|
||||
|
@ -635,9 +627,8 @@ public sealed class StringPool
|
|||
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||
private void UpdateTimestamp(ref int heapIndex)
|
||||
{
|
||||
int
|
||||
currentIndex = heapIndex,
|
||||
count = this.count;
|
||||
int currentIndex = heapIndex;
|
||||
int count = this.count;
|
||||
ref MapEntry mapEntriesRef = ref this.mapEntries.DangerousGetReference();
|
||||
ref HeapEntry heapEntriesRef = ref this.heapEntries.DangerousGetReference();
|
||||
ref HeapEntry root = ref Unsafe.Add(ref heapEntriesRef, (nint)(uint)currentIndex);
|
||||
|
@ -684,10 +675,9 @@ public sealed class StringPool
|
|||
// - left: (2 * n) + 1
|
||||
// - right: (2 * n) + 2
|
||||
ref HeapEntry minimum = ref root;
|
||||
int
|
||||
left = (currentIndex * 2) + 1,
|
||||
right = (currentIndex * 2) + 2,
|
||||
targetIndex = currentIndex;
|
||||
int left = (currentIndex * 2) + 1;
|
||||
int right = (currentIndex * 2) + 2;
|
||||
int targetIndex = currentIndex;
|
||||
|
||||
// Check and update the left child, if necessary
|
||||
if (left < count)
|
||||
|
|
|
@ -223,9 +223,8 @@ public readonly ref struct ReadOnlyRefEnumerable<T>
|
|||
#else
|
||||
ref T sourceRef = ref RuntimeHelpers.GetObjectDataAtOffsetOrPointerReference<T>(this.instance, this.offset);
|
||||
ref T destinationRef = ref RuntimeHelpers.GetObjectDataAtOffsetOrPointerReference<T>(destination.Instance, destination.Offset);
|
||||
int
|
||||
sourceLength = this.length,
|
||||
destinationLength = destination.Length;
|
||||
int sourceLength = this.length;
|
||||
int destinationLength = destination.Length;
|
||||
#endif
|
||||
|
||||
if ((uint)destinationLength < (uint)sourceLength)
|
||||
|
@ -248,9 +247,8 @@ public readonly ref struct ReadOnlyRefEnumerable<T>
|
|||
sourceLength = this.span.Length,
|
||||
destinationLength = destination.Span.Length;
|
||||
#else
|
||||
int
|
||||
sourceLength = this.length,
|
||||
destinationLength = destination.Length;
|
||||
int sourceLength = this.length;
|
||||
int destinationLength = destination.Length;
|
||||
#endif
|
||||
|
||||
if (destinationLength >= sourceLength)
|
||||
|
|
|
@ -67,9 +67,8 @@ public ref struct ReadOnlySpanTokenizer<T>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool MoveNext()
|
||||
{
|
||||
int
|
||||
newEnd = this.end + 1,
|
||||
length = this.span.Length;
|
||||
int newEnd = this.end + 1;
|
||||
int length = this.span.Length;
|
||||
|
||||
// Additional check if the separator is not the last character
|
||||
if (newEnd <= length)
|
||||
|
|
|
@ -230,9 +230,8 @@ public readonly ref struct RefEnumerable<T>
|
|||
#else
|
||||
ref T sourceRef = ref RuntimeHelpers.GetObjectDataAtOffsetOrPointerReference<T>(this.Instance, this.Offset);
|
||||
ref T destinationRef = ref RuntimeHelpers.GetObjectDataAtOffsetOrPointerReference<T>(destination.Instance, destination.Offset);
|
||||
int
|
||||
sourceLength = this.Length,
|
||||
destinationLength = destination.Length;
|
||||
int sourceLength = this.Length;
|
||||
int destinationLength = destination.Length;
|
||||
#endif
|
||||
|
||||
if ((uint)destinationLength < (uint)sourceLength)
|
||||
|
@ -255,9 +254,8 @@ public readonly ref struct RefEnumerable<T>
|
|||
sourceLength = this.Span.Length,
|
||||
destinationLength = destination.Span.Length;
|
||||
#else
|
||||
int
|
||||
sourceLength = this.Length,
|
||||
destinationLength = destination.Length;
|
||||
int sourceLength = this.Length;
|
||||
int destinationLength = destination.Length;
|
||||
#endif
|
||||
|
||||
if (destinationLength >= sourceLength)
|
||||
|
|
|
@ -67,9 +67,8 @@ public ref struct SpanTokenizer<T>
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public bool MoveNext()
|
||||
{
|
||||
int
|
||||
newEnd = this.end + 1,
|
||||
length = this.span.Length;
|
||||
int newEnd = this.end + 1;
|
||||
int length = this.span.Length;
|
||||
|
||||
// Additional check if the separator is not the last character
|
||||
if (newEnd <= length)
|
||||
|
|
|
@ -112,9 +112,8 @@ public static partial class ArrayExtensions
|
|||
where T : IEquatable<T>
|
||||
{
|
||||
ref T r0 = ref array.DangerousGetReference();
|
||||
nint
|
||||
length = RuntimeHelpers.GetArrayNativeLength(array),
|
||||
count = SpanHelper.Count(ref r0, length, value);
|
||||
nint length = RuntimeHelpers.GetArrayNativeLength(array);
|
||||
nint count = SpanHelper.Count(ref r0, length, value);
|
||||
|
||||
if ((nuint)count > int.MaxValue)
|
||||
{
|
||||
|
|
|
@ -394,9 +394,8 @@ public static partial class ArrayExtensions
|
|||
where T : IEquatable<T>
|
||||
{
|
||||
ref T r0 = ref array.DangerousGetReference();
|
||||
nint
|
||||
length = RuntimeHelpers.GetArrayNativeLength(array),
|
||||
count = SpanHelper.Count(ref r0, length, value);
|
||||
nint length = RuntimeHelpers.GetArrayNativeLength(array);
|
||||
nint count = SpanHelper.Count(ref r0, length, value);
|
||||
|
||||
if ((nuint)count > int.MaxValue)
|
||||
{
|
||||
|
|
|
@ -70,11 +70,10 @@ public static partial class ArrayExtensions
|
|||
ref T r0 = ref Unsafe.As<byte, T>(ref arrayData.Data);
|
||||
ref T ri = ref Unsafe.Add(ref r0, offset);
|
||||
|
||||
return ref ri;
|
||||
return ref ri;
|
||||
#else
|
||||
int
|
||||
height = array.GetLength(1),
|
||||
width = array.GetLength(2);
|
||||
int height = array.GetLength(1);
|
||||
int width = array.GetLength(2);
|
||||
nint index =
|
||||
((nint)(uint)i * (nint)(uint)height * (nint)(uint)width) +
|
||||
((nint)(uint)j * (nint)(uint)width) + (nint)(uint)k;
|
||||
|
@ -267,9 +266,8 @@ public static partial class ArrayExtensions
|
|||
where T : IEquatable<T>
|
||||
{
|
||||
ref T r0 = ref array.DangerousGetReference();
|
||||
nint
|
||||
length = RuntimeHelpers.GetArrayNativeLength(array),
|
||||
count = SpanHelper.Count(ref r0, length, value);
|
||||
nint length = RuntimeHelpers.GetArrayNativeLength(array);
|
||||
nint count = SpanHelper.Count(ref r0, length, value);
|
||||
|
||||
if ((nuint)count > int.MaxValue)
|
||||
{
|
||||
|
|
|
@ -52,9 +52,8 @@ public static class BoolExtensions
|
|||
{
|
||||
bool copy = flag;
|
||||
byte rangeFlag = *(byte*)©
|
||||
int
|
||||
negativeFlag = rangeFlag - 1,
|
||||
mask = ~negativeFlag;
|
||||
int negativeFlag = rangeFlag - 1;
|
||||
int mask = ~negativeFlag;
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
@ -72,9 +71,8 @@ public static class BoolExtensions
|
|||
{
|
||||
bool copy = flag;
|
||||
byte rangeFlag = *(byte*)©
|
||||
long
|
||||
negativeFlag = (long)rangeFlag - 1,
|
||||
mask = ~negativeFlag;
|
||||
long negativeFlag = (long)rangeFlag - 1;
|
||||
long mask = ~negativeFlag;
|
||||
|
||||
return mask;
|
||||
}
|
||||
|
|
|
@ -154,10 +154,9 @@ public static class ReadOnlySpanExtensions
|
|||
// lookup table can just be assumed to always be false.
|
||||
bool isInRange = (uint)i < (uint)span.Length;
|
||||
byte rangeFlag = *(byte*)&isInRange;
|
||||
uint
|
||||
negativeFlag = unchecked(rangeFlag - 1u),
|
||||
mask = ~negativeFlag,
|
||||
offset = (uint)i & mask;
|
||||
uint negativeFlag = unchecked(rangeFlag - 1u);
|
||||
uint mask = ~negativeFlag;
|
||||
uint offset = (uint)i & mask;
|
||||
ref T r0 = ref MemoryMarshal.GetReference(span);
|
||||
ref T r1 = ref Unsafe.Add(ref r0, (nint)offset);
|
||||
|
||||
|
|
|
@ -92,11 +92,10 @@ public static class BitHelper
|
|||
int i = x - min;
|
||||
bool isInRange = (uint)i < 32u;
|
||||
byte byteFlag = *(byte*)&isInRange;
|
||||
int
|
||||
negativeFlag = byteFlag - 1,
|
||||
mask = ~negativeFlag,
|
||||
shift = unchecked((int)((table >> i) & 1)),
|
||||
and = shift & mask;
|
||||
int negativeFlag = byteFlag - 1;
|
||||
int mask = ~negativeFlag;
|
||||
int shift = unchecked((int)((table >> i) & 1));
|
||||
int and = shift & mask;
|
||||
byte result = unchecked((byte)and);
|
||||
bool valid = *(bool*)&result;
|
||||
|
||||
|
@ -199,10 +198,9 @@ public static class BitHelper
|
|||
// Shift a bit left to the n-th position, negate the
|
||||
// resulting value and perform an AND with the input value.
|
||||
// This effectively clears the n-th bit of our input.
|
||||
uint
|
||||
bit = 1u << n,
|
||||
not = ~bit,
|
||||
and = value & not;
|
||||
uint bit = 1u << n;
|
||||
uint not = ~bit;
|
||||
uint and = value & not;
|
||||
|
||||
// Reinterpret the flag as 1 or 0, and cast to uint,
|
||||
// then we left shift the uint flag to the right position
|
||||
|
@ -210,10 +208,9 @@ public static class BitHelper
|
|||
// operation. This will always guaranteed to work, thanks to the
|
||||
// initial code clearing that bit before setting it again.
|
||||
bool copy = flag;
|
||||
uint
|
||||
flag32 = *(byte*)©,
|
||||
shift = flag32 << n,
|
||||
or = and | shift;
|
||||
uint flag32 = *(byte*)©
|
||||
uint shift = flag32 << n;
|
||||
uint or = and | shift;
|
||||
|
||||
return or;
|
||||
}
|
||||
|
@ -279,10 +276,9 @@ public static class BitHelper
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static uint SetRange(uint value, byte start, byte length, uint flags)
|
||||
{
|
||||
uint
|
||||
highBits = (1u << length) - 1u,
|
||||
loadMask = highBits << start,
|
||||
storeMask = (flags & highBits) << start;
|
||||
uint highBits = (1u << length) - 1u;
|
||||
uint loadMask = highBits << start;
|
||||
uint storeMask = (flags & highBits) << start;
|
||||
|
||||
#if NETCOREAPP3_1 || NET5_0
|
||||
if (Bmi1.IsSupported)
|
||||
|
@ -334,11 +330,10 @@ public static class BitHelper
|
|||
int i = x - min;
|
||||
bool isInRange = (uint)i < 64u;
|
||||
byte byteFlag = *(byte*)&isInRange;
|
||||
int
|
||||
negativeFlag = byteFlag - 1,
|
||||
mask = ~negativeFlag,
|
||||
shift = unchecked((int)((table >> i) & 1)),
|
||||
and = shift & mask;
|
||||
int negativeFlag = byteFlag - 1;
|
||||
int mask = ~negativeFlag;
|
||||
int shift = unchecked((int)((table >> i) & 1));
|
||||
int and = shift & mask;
|
||||
byte result = unchecked((byte)and);
|
||||
bool valid = *(bool*)&result;
|
||||
|
||||
|
@ -376,14 +371,13 @@ public static class BitHelper
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static unsafe ulong SetFlag(ulong value, int n, bool flag)
|
||||
{
|
||||
ulong
|
||||
bit = 1ul << n,
|
||||
not = ~bit,
|
||||
and = value & not;
|
||||
ulong bit = 1ul << n;
|
||||
ulong not = ~bit;
|
||||
ulong and = value & not;
|
||||
bool copy = flag;
|
||||
ulong flag64 = *(byte*)©,
|
||||
shift = flag64 << n,
|
||||
or = and | shift;
|
||||
ulong flag64 = *(byte*)©
|
||||
ulong shift = flag64 << n;
|
||||
ulong or = and | shift;
|
||||
|
||||
return or;
|
||||
}
|
||||
|
@ -449,10 +443,9 @@ public static class BitHelper
|
|||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static ulong SetRange(ulong value, byte start, byte length, ulong flags)
|
||||
{
|
||||
ulong
|
||||
highBits = (1ul << length) - 1ul,
|
||||
loadMask = highBits << start,
|
||||
storeMask = (flags & highBits) << start;
|
||||
ulong highBits = (1ul << length) - 1ul;
|
||||
ulong loadMask = highBits << start;
|
||||
ulong storeMask = (flags & highBits) << start;
|
||||
|
||||
#if NETCOREAPP3_1 || NET5_0
|
||||
if (Bmi1.X64.IsSupported)
|
||||
|
|
|
@ -69,9 +69,8 @@ internal static class RefEnumerableHelper
|
|||
/// <param name="sourceStep">The step between consecutive items in the memory area pointed to by <paramref name="sourceRef"/>.</param>
|
||||
public static void CopyTo<T>(ref T sourceRef, ref T destinationRef, nint length, nint sourceStep)
|
||||
{
|
||||
nint
|
||||
sourceOffset = 0,
|
||||
destinationOffset = 0;
|
||||
nint sourceOffset = 0;
|
||||
nint destinationOffset = 0;
|
||||
|
||||
while (length >= 8)
|
||||
{
|
||||
|
@ -122,9 +121,8 @@ internal static class RefEnumerableHelper
|
|||
/// <param name="destinationStep">The step between consecutive items in the memory area pointed to by <paramref name="destinationRef"/>.</param>
|
||||
public static void CopyTo<T>(ref T sourceRef, ref T destinationRef, nint length, nint sourceStep, nint destinationStep)
|
||||
{
|
||||
nint
|
||||
sourceOffset = 0,
|
||||
destinationOffset = 0;
|
||||
nint sourceOffset = 0;
|
||||
nint destinationOffset = 0;
|
||||
|
||||
while (length >= 8)
|
||||
{
|
||||
|
@ -175,9 +173,8 @@ internal static class RefEnumerableHelper
|
|||
/// <param name="sourceStep">The step between consecutive items in the memory area pointed to by <paramref name="sourceRef"/>.</param>
|
||||
public static void CopyFrom<T>(ref T sourceRef, ref T destinationRef, nint length, nint sourceStep)
|
||||
{
|
||||
nint
|
||||
sourceOffset = 0,
|
||||
destinationOffset = 0;
|
||||
nint sourceOffset = 0;
|
||||
nint destinationOffset = 0;
|
||||
|
||||
while (length >= 8)
|
||||
{
|
||||
|
|
|
@ -81,9 +81,8 @@ internal static partial class SpanHelper
|
|||
private static nint CountSequential<T>(ref T r0, nint length, T value)
|
||||
where T : IEquatable<T>
|
||||
{
|
||||
nint
|
||||
result = 0,
|
||||
offset = 0;
|
||||
nint result = 0;
|
||||
nint offset = 0;
|
||||
|
||||
// Main loop with 8 unrolled iterations
|
||||
while (length >= 8)
|
||||
|
@ -131,9 +130,8 @@ internal static partial class SpanHelper
|
|||
private static nint CountSimd<T>(ref T r0, nint length, T value)
|
||||
where T : unmanaged, IEquatable<T>
|
||||
{
|
||||
nint
|
||||
result = 0,
|
||||
offset = 0;
|
||||
nint result = 0;
|
||||
nint offset = 0;
|
||||
|
||||
// Skip the initialization overhead if there are not enough items
|
||||
if (length >= Vector<T>.Count)
|
||||
|
@ -147,10 +145,9 @@ internal static partial class SpanHelper
|
|||
// to sum the partial results. We also backup the current offset to
|
||||
// be able to track how many items have been processed, which lets
|
||||
// us avoid updating a third counter (length) in the loop body.
|
||||
nint
|
||||
max = GetUpperBound<T>(),
|
||||
chunkLength = length <= max ? length : max,
|
||||
initialOffset = offset;
|
||||
nint max = GetUpperBound<T>();
|
||||
nint chunkLength = length <= max ? length : max;
|
||||
nint initialOffset = offset;
|
||||
|
||||
Vector<T> partials = Vector<T>.Zero;
|
||||
|
||||
|
|
|
@ -80,9 +80,8 @@ public static partial class ParallelHelper
|
|||
ThrowArgumentExceptionForRangeIndexFromEnd(nameof(range));
|
||||
}
|
||||
|
||||
int
|
||||
start = range.Start.Value,
|
||||
end = range.End.Value;
|
||||
int start = range.Start.Value;
|
||||
int end = range.End.Value;
|
||||
|
||||
For(start, end, action, minimumActionsPerThread);
|
||||
}
|
||||
|
@ -163,11 +162,10 @@ public static partial class ParallelHelper
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
count = Math.Abs(start - end),
|
||||
maxBatches = 1 + ((count - 1) / minimumActionsPerThread),
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = Math.Min(maxBatches, cores);
|
||||
int count = Math.Abs(start - end);
|
||||
int maxBatches = 1 + ((count - 1) / minimumActionsPerThread);
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = Math.Min(maxBatches, cores);
|
||||
|
||||
// Skip the parallel invocation when a single batch is needed
|
||||
if (numBatches == 1)
|
||||
|
@ -220,11 +218,10 @@ public static partial class ParallelHelper
|
|||
/// <param name="i">The index of the batch to process</param>
|
||||
public void Invoke(int i)
|
||||
{
|
||||
int
|
||||
offset = i * this.batchSize,
|
||||
low = this.start + offset,
|
||||
high = low + this.batchSize,
|
||||
stop = Math.Min(high, this.end);
|
||||
int offset = i * this.batchSize;
|
||||
int low = this.start + offset;
|
||||
int high = low + this.batchSize;
|
||||
int stop = Math.Min(high, this.end);
|
||||
|
||||
for (int j = low; j < stop; j++)
|
||||
{
|
||||
|
|
|
@ -86,11 +86,10 @@ public static partial class ParallelHelper
|
|||
ThrowArgumentExceptionForRangeIndexFromEnd(nameof(j));
|
||||
}
|
||||
|
||||
int
|
||||
top = i.Start.Value,
|
||||
bottom = i.End.Value,
|
||||
left = j.Start.Value,
|
||||
right = j.End.Value;
|
||||
int top = i.Start.Value;
|
||||
int bottom = i.End.Value;
|
||||
int left = j.Start.Value;
|
||||
int right = j.End.Value;
|
||||
|
||||
For2D(top, bottom, left, right, action, minimumActionsPerThread);
|
||||
}
|
||||
|
@ -245,14 +244,13 @@ public static partial class ParallelHelper
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
height = Math.Abs(top - bottom),
|
||||
width = Math.Abs(left - right),
|
||||
count = height * width,
|
||||
maxBatches = 1 + ((count - 1) / minimumActionsPerThread),
|
||||
clipBatches = Math.Min(maxBatches, height),
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = Math.Min(clipBatches, cores);
|
||||
int height = Math.Abs(top - bottom);
|
||||
int width = Math.Abs(left - right);
|
||||
int count = height * width;
|
||||
int maxBatches = 1 + ((count - 1) / minimumActionsPerThread);
|
||||
int clipBatches = Math.Min(maxBatches, height);
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = Math.Min(clipBatches, cores);
|
||||
|
||||
// Skip the parallel invocation when a single batch is needed
|
||||
if (numBatches == 1)
|
||||
|
@ -314,11 +312,10 @@ public static partial class ParallelHelper
|
|||
/// <param name="i">The index of the batch to process</param>
|
||||
public void Invoke(int i)
|
||||
{
|
||||
int
|
||||
heightOffset = i * this.batchHeight,
|
||||
lowY = this.startY + heightOffset,
|
||||
highY = lowY + this.batchHeight,
|
||||
stopY = Math.Min(highY, this.endY);
|
||||
int heightOffset = i * this.batchHeight;
|
||||
int lowY = this.startY + heightOffset;
|
||||
int highY = lowY + this.batchHeight;
|
||||
int stopY = Math.Min(highY, this.endY);
|
||||
|
||||
for (int y = lowY; y < stopY; y++)
|
||||
{
|
||||
|
|
|
@ -84,10 +84,9 @@ public static partial class ParallelHelper
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread),
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = Math.Min(maxBatches, cores);
|
||||
int maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread);
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = Math.Min(maxBatches, cores);
|
||||
|
||||
// Skip the parallel invocation when a single batch is needed
|
||||
if (numBatches == 1)
|
||||
|
@ -137,10 +136,9 @@ public static partial class ParallelHelper
|
|||
/// <param name="i">The index of the batch to process</param>
|
||||
public void Invoke(int i)
|
||||
{
|
||||
int
|
||||
low = i * this.batchSize,
|
||||
high = low + this.batchSize,
|
||||
end = Math.Min(high, this.memory.Length);
|
||||
int low = i * this.batchSize;
|
||||
int high = low + this.batchSize;
|
||||
int end = Math.Min(high, this.memory.Length);
|
||||
|
||||
ref TItem r0 = ref MemoryMarshal.GetReference(this.memory.Span);
|
||||
ref TItem rStart = ref Unsafe.Add(ref r0, low);
|
||||
|
|
|
@ -83,13 +83,11 @@ public static partial class ParallelHelper
|
|||
return;
|
||||
}
|
||||
|
||||
nint
|
||||
maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread),
|
||||
clipBatches = maxBatches <= memory.Height ? maxBatches : memory.Height;
|
||||
int
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = (int)(clipBatches <= cores ? clipBatches : cores),
|
||||
batchHeight = 1 + ((memory.Height - 1) / numBatches);
|
||||
nint maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread);
|
||||
nint clipBatches = maxBatches <= memory.Height ? maxBatches : memory.Height;
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = (int)(clipBatches <= cores ? clipBatches : cores);
|
||||
int batchHeight = 1 + ((memory.Height - 1) / numBatches);
|
||||
|
||||
InActionInvokerWithReadOnlyMemory2D<TItem, TAction> actionInvoker = new(batchHeight, memory, action);
|
||||
|
||||
|
@ -136,9 +134,8 @@ public static partial class ParallelHelper
|
|||
{
|
||||
int lowY = i * this.batchHeight;
|
||||
nint highY = lowY + this.batchHeight;
|
||||
int
|
||||
stopY = (int)(highY <= this.memory.Height ? highY : this.memory.Height),
|
||||
width = this.memory.Width;
|
||||
int stopY = (int)(highY <= this.memory.Height ? highY : this.memory.Height);
|
||||
int width = this.memory.Width;
|
||||
|
||||
ReadOnlySpan2D<TItem> span = this.memory.Span;
|
||||
|
||||
|
|
|
@ -84,10 +84,9 @@ public static partial class ParallelHelper
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread),
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = Math.Min(maxBatches, cores);
|
||||
int maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread);
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = Math.Min(maxBatches, cores);
|
||||
|
||||
// Skip the parallel invocation when a single batch is needed
|
||||
if (numBatches == 1)
|
||||
|
@ -137,10 +136,9 @@ public static partial class ParallelHelper
|
|||
/// <param name="i">The index of the batch to process</param>
|
||||
public void Invoke(int i)
|
||||
{
|
||||
int
|
||||
low = i * this.batchSize,
|
||||
high = low + this.batchSize,
|
||||
end = Math.Min(high, this.memory.Length);
|
||||
int low = i * this.batchSize;
|
||||
int high = low + this.batchSize;
|
||||
int end = Math.Min(high, this.memory.Length);
|
||||
|
||||
ref TItem r0 = ref MemoryMarshal.GetReference(this.memory.Span);
|
||||
ref TItem rStart = ref Unsafe.Add(ref r0, low);
|
||||
|
|
|
@ -90,13 +90,11 @@ public static partial class ParallelHelper
|
|||
// of CPU cores (which is an int), and the height of each batch is necessarily
|
||||
// smaller than or equal than int.MaxValue, as it can't be greater than the
|
||||
// number of total batches, which again is capped at the number of CPU cores.
|
||||
nint
|
||||
maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread),
|
||||
clipBatches = maxBatches <= memory.Height ? maxBatches : memory.Height;
|
||||
int
|
||||
cores = Environment.ProcessorCount,
|
||||
numBatches = (int)(clipBatches <= cores ? clipBatches : cores),
|
||||
batchHeight = 1 + ((memory.Height - 1) / numBatches);
|
||||
nint maxBatches = 1 + ((memory.Length - 1) / minimumActionsPerThread);
|
||||
nint clipBatches = maxBatches <= memory.Height ? maxBatches : memory.Height;
|
||||
int cores = Environment.ProcessorCount;
|
||||
int numBatches = (int)(clipBatches <= cores ? clipBatches : cores);
|
||||
int batchHeight = 1 + ((memory.Height - 1) / numBatches);
|
||||
|
||||
RefActionInvokerWithReadOnlyMemory2D<TItem, TAction> actionInvoker = new(batchHeight, memory, action);
|
||||
|
||||
|
@ -143,9 +141,8 @@ public static partial class ParallelHelper
|
|||
{
|
||||
int lowY = i * this.batchHeight;
|
||||
nint highY = lowY + this.batchHeight;
|
||||
int
|
||||
stopY = (int)(highY <= this.memory.Height ? highY : this.memory.Height),
|
||||
width = this.memory.Width;
|
||||
int stopY = (int)(highY <= this.memory.Height ? highY : this.memory.Height);
|
||||
int width = this.memory.Width;
|
||||
|
||||
ReadOnlySpan2D<TItem> span = this.memory.Span;
|
||||
|
||||
|
|
|
@ -119,9 +119,8 @@ public readonly struct Memory2D<T> : IEquatable<Memory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForPitch();
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = array.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = array.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -197,9 +196,8 @@ public readonly struct Memory2D<T> : IEquatable<Memory2D<T>>
|
|||
ThrowHelper.ThrowArrayTypeMismatchException();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(0),
|
||||
columns = array.GetLength(1);
|
||||
int rows = array.GetLength(0);
|
||||
int columns = array.GetLength(1);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -281,9 +279,8 @@ public readonly struct Memory2D<T> : IEquatable<Memory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(1),
|
||||
columns = array.GetLength(2);
|
||||
int rows = array.GetLength(1);
|
||||
int columns = array.GetLength(2);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -373,9 +370,8 @@ public readonly struct Memory2D<T> : IEquatable<Memory2D<T>>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -686,9 +682,8 @@ public readonly struct Memory2D<T> : IEquatable<Memory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForWidth();
|
||||
}
|
||||
|
||||
int
|
||||
shift = ((this.width + this.pitch) * row) + column,
|
||||
pitch = this.pitch + (this.width - width);
|
||||
int shift = ((this.width + this.pitch) * row) + column;
|
||||
int pitch = this.pitch + (this.width - width);
|
||||
|
||||
IntPtr offset = this.offset + (shift * Unsafe.SizeOf<T>());
|
||||
|
||||
|
|
|
@ -105,9 +105,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForPitch();
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = text.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = text.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -172,9 +171,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForPitch();
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = array.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = array.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -234,9 +232,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(0),
|
||||
columns = array.GetLength(1);
|
||||
int rows = array.GetLength(0);
|
||||
int columns = array.GetLength(1);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -302,9 +299,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(1),
|
||||
columns = array.GetLength(2);
|
||||
int rows = array.GetLength(1);
|
||||
int columns = array.GetLength(2);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -394,9 +390,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -468,9 +463,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = memory.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = memory.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -701,9 +695,8 @@ public readonly struct ReadOnlyMemory2D<T> : IEquatable<ReadOnlyMemory2D<T>>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForWidth();
|
||||
}
|
||||
|
||||
int
|
||||
shift = ((this.width + this.pitch) * row) + column,
|
||||
pitch = this.pitch + (this.width - width);
|
||||
int shift = ((this.width + this.pitch) * row) + column;
|
||||
int pitch = this.pitch + (this.width - width);
|
||||
|
||||
IntPtr offset = this.offset + (shift * Unsafe.SizeOf<T>());
|
||||
|
||||
|
|
|
@ -199,9 +199,8 @@ public readonly ref partial struct ReadOnlySpan2D<T>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = array.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = array.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -268,9 +267,8 @@ public readonly ref partial struct ReadOnlySpan2D<T>
|
|||
return;
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(0),
|
||||
columns = array.GetLength(1);
|
||||
int rows = array.GetLength(0);
|
||||
int columns = array.GetLength(1);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -343,9 +341,8 @@ public readonly ref partial struct ReadOnlySpan2D<T>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(1),
|
||||
columns = array.GetLength(2);
|
||||
int rows = array.GetLength(1);
|
||||
int columns = array.GetLength(2);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
|
|
@ -238,9 +238,8 @@ public readonly ref partial struct Span2D<T>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForPitch();
|
||||
}
|
||||
|
||||
int
|
||||
area = OverflowHelper.ComputeInt32Area(height, width, pitch),
|
||||
remaining = array.Length - offset;
|
||||
int area = OverflowHelper.ComputeInt32Area(height, width, pitch);
|
||||
int remaining = array.Length - offset;
|
||||
|
||||
if (area > remaining)
|
||||
{
|
||||
|
@ -323,9 +322,8 @@ public readonly ref partial struct Span2D<T>
|
|||
ThrowHelper.ThrowArrayTypeMismatchException();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(0),
|
||||
columns = array.GetLength(1);
|
||||
int rows = array.GetLength(0);
|
||||
int columns = array.GetLength(1);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
@ -414,9 +412,8 @@ public readonly ref partial struct Span2D<T>
|
|||
ThrowHelper.ThrowArgumentOutOfRangeExceptionForDepth();
|
||||
}
|
||||
|
||||
int
|
||||
rows = array.GetLength(1),
|
||||
columns = array.GetLength(2);
|
||||
int rows = array.GetLength(1);
|
||||
int columns = array.GetLength(2);
|
||||
|
||||
if ((uint)row >= (uint)rows)
|
||||
{
|
||||
|
|
|
@ -142,9 +142,8 @@ internal sealed partial class IBufferWriterStream<TWriter> : Stream
|
|||
MemoryStream.ValidateDisposed(this.disposed);
|
||||
MemoryStream.ValidateBuffer(buffer, offset, count);
|
||||
|
||||
Span<byte>
|
||||
source = buffer.AsSpan(offset, count),
|
||||
destination = this.bufferWriter.GetSpan(count);
|
||||
Span<byte> source = buffer.AsSpan(offset, count);
|
||||
Span<byte> destination = this.bufferWriter.GetSpan(count);
|
||||
|
||||
if (!source.TryCopyTo(destination))
|
||||
{
|
||||
|
|
|
@ -229,13 +229,11 @@ internal partial class MemoryStream<TSource> : Stream
|
|||
MemoryStream.ValidateDisposed(this.disposed);
|
||||
MemoryStream.ValidateBuffer(buffer, offset, count);
|
||||
|
||||
int
|
||||
bytesAvailable = this.source.Length - this.position,
|
||||
bytesCopied = Math.Min(bytesAvailable, count);
|
||||
int bytesAvailable = this.source.Length - this.position;
|
||||
int bytesCopied = Math.Min(bytesAvailable, count);
|
||||
|
||||
Span<byte>
|
||||
source = this.source.Span.Slice(this.position, bytesCopied),
|
||||
destination = buffer.AsSpan(offset, bytesCopied);
|
||||
Span<byte> source = this.source.Span.Slice(this.position, bytesCopied);
|
||||
Span<byte> destination = buffer.AsSpan(offset, bytesCopied);
|
||||
|
||||
source.CopyTo(destination);
|
||||
|
||||
|
@ -264,9 +262,8 @@ internal partial class MemoryStream<TSource> : Stream
|
|||
MemoryStream.ValidateCanWrite(CanWrite);
|
||||
MemoryStream.ValidateBuffer(buffer, offset, count);
|
||||
|
||||
Span<byte>
|
||||
source = buffer.AsSpan(offset, count),
|
||||
destination = this.source.Span.Slice(this.position);
|
||||
Span<byte> source = buffer.AsSpan(offset, count);
|
||||
Span<byte> destination = this.source.Span.Slice(this.position);
|
||||
|
||||
if (!source.TryCopyTo(destination))
|
||||
{
|
||||
|
|
|
@ -43,16 +43,14 @@ public sealed class NullabilityAttributesGenerator : ISourceGenerator
|
|||
return;
|
||||
}
|
||||
|
||||
string
|
||||
typeName = typeFullName.Split('.').Last(),
|
||||
filename = $"CommunityToolkit.Mvvm.SourceGenerators.EmbeddedResources.{typeName}.cs";
|
||||
string typeName = typeFullName.Split('.').Last();
|
||||
string filename = $"CommunityToolkit.Mvvm.SourceGenerators.EmbeddedResources.{typeName}.cs";
|
||||
|
||||
Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(filename);
|
||||
StreamReader reader = new(stream);
|
||||
|
||||
string
|
||||
originalSource = reader.ReadToEnd(),
|
||||
outputSource = originalSource.Replace("NETSTANDARD2_0", "true");
|
||||
string originalSource = reader.ReadToEnd();
|
||||
string outputSource = originalSource.Replace("NETSTANDARD2_0", "true");
|
||||
|
||||
context.AddSource($"{typeFullName}.cs", SourceText.From(outputSource, Encoding.UTF8));
|
||||
}
|
||||
|
|
|
@ -35,9 +35,8 @@ public sealed class ObservableObjectGenerator : TransitiveMembersGenerator
|
|||
INamedTypeSymbol classDeclarationSymbol,
|
||||
[NotNullWhen(false)] out DiagnosticDescriptor? descriptor)
|
||||
{
|
||||
INamedTypeSymbol
|
||||
iNotifyPropertyChangedSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged")!,
|
||||
iNotifyPropertyChangingSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanging")!;
|
||||
INamedTypeSymbol iNotifyPropertyChangedSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged")!;
|
||||
INamedTypeSymbol iNotifyPropertyChangingSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanging")!;
|
||||
|
||||
// Check if the type already implements INotifyPropertyChanged...
|
||||
if (classDeclarationSymbol.AllInterfaces.Any(i => SymbolEqualityComparer.Default.Equals(i, iNotifyPropertyChangedSymbol)))
|
||||
|
|
|
@ -51,9 +51,8 @@ public sealed partial class ObservablePropertyGenerator : ISourceGenerator
|
|||
}
|
||||
|
||||
// Sets of discovered property names
|
||||
HashSet<string>
|
||||
propertyChangedNames = new(),
|
||||
propertyChangingNames = new();
|
||||
HashSet<string> propertyChangedNames = new();
|
||||
HashSet<string> propertyChangingNames = new();
|
||||
|
||||
// Process the annotated fields
|
||||
foreach (IGrouping<INamedTypeSymbol, SyntaxReceiver.Item>? items in syntaxReceiver.GatheredInfo.GroupBy<SyntaxReceiver.Item, INamedTypeSymbol>(static item => item.FieldSymbol.ContainingType, SymbolEqualityComparer.Default))
|
||||
|
@ -93,17 +92,15 @@ public sealed partial class ObservablePropertyGenerator : ISourceGenerator
|
|||
ICollection<string> propertyChangedNames,
|
||||
ICollection<string> propertyChangingNames)
|
||||
{
|
||||
INamedTypeSymbol
|
||||
iNotifyPropertyChangingSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanging")!,
|
||||
observableObjectSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObject")!,
|
||||
observableObjectAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObjectAttribute")!,
|
||||
observableValidatorSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableValidator")!;
|
||||
INamedTypeSymbol iNotifyPropertyChangingSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanging")!;
|
||||
INamedTypeSymbol observableObjectSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObject")!;
|
||||
INamedTypeSymbol observableObjectAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObjectAttribute")!;
|
||||
INamedTypeSymbol observableValidatorSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableValidator")!;
|
||||
|
||||
// Check whether the current type implements INotifyPropertyChanging and whether it inherits from ObservableValidator
|
||||
bool
|
||||
isObservableObject = classDeclarationSymbol.InheritsFrom(observableObjectSymbol),
|
||||
isObservableValidator = classDeclarationSymbol.InheritsFrom(observableValidatorSymbol),
|
||||
isNotifyPropertyChanging =
|
||||
bool isObservableObject = classDeclarationSymbol.InheritsFrom(observableObjectSymbol);
|
||||
bool isObservableValidator = classDeclarationSymbol.InheritsFrom(observableValidatorSymbol);
|
||||
bool isNotifyPropertyChanging =
|
||||
isObservableObject ||
|
||||
classDeclarationSymbol.AllInterfaces.Contains(iNotifyPropertyChangingSymbol, SymbolEqualityComparer.Default) ||
|
||||
classDeclarationSymbol.GetAttributes().Any(a => SymbolEqualityComparer.Default.Equals(a.AttributeClass, observableObjectAttributeSymbol));
|
||||
|
@ -182,9 +179,8 @@ public sealed partial class ObservablePropertyGenerator : ISourceGenerator
|
|||
ICollection<string> propertyChangingNames)
|
||||
{
|
||||
// Get the field type and the target property name
|
||||
string
|
||||
typeName = fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat),
|
||||
propertyName = GetGeneratedPropertyName(fieldSymbol);
|
||||
string typeName = fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
|
||||
string propertyName = GetGeneratedPropertyName(fieldSymbol);
|
||||
|
||||
INamedTypeSymbol alsoNotifyChangeForAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.AlsoNotifyChangeForAttribute")!;
|
||||
INamedTypeSymbol? validationAttributeSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute");
|
||||
|
@ -489,9 +485,8 @@ public sealed partial class ObservablePropertyGenerator : ISourceGenerator
|
|||
return;
|
||||
}
|
||||
|
||||
INamedTypeSymbol
|
||||
propertyChangedEventArgsSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.PropertyChangedEventArgs")!,
|
||||
propertyChangingEventArgsSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.PropertyChangingEventArgs")!;
|
||||
INamedTypeSymbol propertyChangedEventArgsSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.PropertyChangedEventArgs")!;
|
||||
INamedTypeSymbol propertyChangingEventArgsSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.PropertyChangingEventArgs")!;
|
||||
|
||||
// Create a static method to validate all properties in a given class.
|
||||
// This code takes a class symbol and produces a compilation unit as follows:
|
||||
|
|
|
@ -39,11 +39,10 @@ public sealed class ObservableRecipientGenerator : TransitiveMembersGenerator
|
|||
INamedTypeSymbol classDeclarationSymbol,
|
||||
[NotNullWhen(false)] out DiagnosticDescriptor? descriptor)
|
||||
{
|
||||
INamedTypeSymbol
|
||||
observableRecipientSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient")!,
|
||||
observableObjectSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObject")!,
|
||||
observableObjectAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObjectAttribute")!,
|
||||
iNotifyPropertyChangedSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged")!;
|
||||
INamedTypeSymbol observableRecipientSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableRecipient")!;
|
||||
INamedTypeSymbol observableObjectSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObject")!;
|
||||
INamedTypeSymbol observableObjectAttributeSymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservableObjectAttribute")!;
|
||||
INamedTypeSymbol iNotifyPropertyChangedSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.INotifyPropertyChanged")!;
|
||||
|
||||
// Check if the type already inherits from ObservableRecipient
|
||||
if (classDeclarationSymbol.InheritsFrom(observableRecipientSymbol))
|
||||
|
@ -90,9 +89,8 @@ public sealed class ObservableRecipientGenerator : TransitiveMembersGenerator
|
|||
{
|
||||
foreach (ConstructorDeclarationSyntax ctor in sourceDeclaration.Members.OfType<ConstructorDeclarationSyntax>())
|
||||
{
|
||||
string
|
||||
text = ctor.NormalizeWhitespace().ToFullString(),
|
||||
replaced = text.Replace("ObservableRecipient", classDeclarationSymbol.Name);
|
||||
string text = ctor.NormalizeWhitespace().ToFullString();
|
||||
string replaced = text.Replace("ObservableRecipient", classDeclarationSymbol.Name);
|
||||
|
||||
// Adjust the visibility of the constructors based on whether the target type is abstract.
|
||||
// If that is not the case, the constructors have to be declared as public and not protected.
|
||||
|
|
|
@ -47,9 +47,8 @@ public sealed partial class ObservableValidatorValidateAllPropertiesGenerator :
|
|||
}
|
||||
|
||||
// Get the symbol for the required attributes
|
||||
INamedTypeSymbol
|
||||
validationSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute")!,
|
||||
observablePropertySymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute")!;
|
||||
INamedTypeSymbol validationSymbol = context.Compilation.GetTypeByMetadataName("System.ComponentModel.DataAnnotations.ValidationAttribute")!;
|
||||
INamedTypeSymbol observablePropertySymbol = context.Compilation.GetTypeByMetadataName("CommunityToolkit.Mvvm.ComponentModel.ObservablePropertyAttribute")!;
|
||||
|
||||
// Prepare the attributes to add to the first class declaration
|
||||
AttributeListSyntax[] classAttributes = new[]
|
||||
|
|
|
@ -168,10 +168,9 @@ public static class IMessengerExtensions
|
|||
}
|
||||
|
||||
// Input parameters (IMessenger instance, non-generic recipient, token)
|
||||
ParameterExpression
|
||||
arg0 = Expression.Parameter(typeof(IMessenger)),
|
||||
arg1 = Expression.Parameter(typeof(object)),
|
||||
arg2 = Expression.Parameter(typeof(TToken));
|
||||
ParameterExpression arg0 = Expression.Parameter(typeof(IMessenger));
|
||||
ParameterExpression arg1 = Expression.Parameter(typeof(object));
|
||||
ParameterExpression arg2 = Expression.Parameter(typeof(TToken));
|
||||
|
||||
// Declare a local resulting from the (RecipientType)recipient cast
|
||||
UnaryExpression inst1 = Expression.Convert(arg1, recipientType);
|
||||
|
|
|
@ -103,26 +103,25 @@ public class Test_StringPool
|
|||
{
|
||||
StringPool? pool = new();
|
||||
|
||||
string
|
||||
hello = nameof(hello),
|
||||
helloworld = nameof(helloworld),
|
||||
windowsCommunityToolkit = nameof(windowsCommunityToolkit);
|
||||
string hello = nameof(hello);
|
||||
string helloworld = nameof(helloworld);
|
||||
string dotnetCommunityToolkit = nameof(dotnetCommunityToolkit);
|
||||
|
||||
Assert.IsFalse(pool.TryGet(hello.AsSpan(), out _));
|
||||
Assert.IsFalse(pool.TryGet(helloworld.AsSpan(), out _));
|
||||
Assert.IsFalse(pool.TryGet(windowsCommunityToolkit.AsSpan(), out _));
|
||||
Assert.IsFalse(pool.TryGet(dotnetCommunityToolkit.AsSpan(), out _));
|
||||
|
||||
pool.Add(hello);
|
||||
pool.Add(helloworld);
|
||||
pool.Add(windowsCommunityToolkit);
|
||||
pool.Add(dotnetCommunityToolkit);
|
||||
|
||||
Assert.IsTrue(pool.TryGet(hello.AsSpan(), out string? hello2));
|
||||
Assert.IsTrue(pool.TryGet(helloworld.AsSpan(), out string? world2));
|
||||
Assert.IsTrue(pool.TryGet(windowsCommunityToolkit.AsSpan(), out string? windowsCommunityToolkit2));
|
||||
Assert.IsTrue(pool.TryGet(dotnetCommunityToolkit.AsSpan(), out string? windowsCommunityToolkit2));
|
||||
|
||||
Assert.AreSame(hello, hello2);
|
||||
Assert.AreSame(helloworld, world2);
|
||||
Assert.AreSame(windowsCommunityToolkit, windowsCommunityToolkit2);
|
||||
Assert.AreSame(dotnetCommunityToolkit, windowsCommunityToolkit2);
|
||||
}
|
||||
|
||||
[TestCategory("StringPool")]
|
||||
|
@ -210,28 +209,27 @@ public class Test_StringPool
|
|||
{
|
||||
StringPool? pool = new();
|
||||
|
||||
string
|
||||
hello = pool.GetOrAdd(nameof(hello).AsSpan()),
|
||||
helloworld = pool.GetOrAdd(nameof(helloworld).AsSpan()),
|
||||
windowsCommunityToolkit = pool.GetOrAdd(nameof(windowsCommunityToolkit).AsSpan());
|
||||
string hello = pool.GetOrAdd(nameof(hello).AsSpan());
|
||||
string helloworld = pool.GetOrAdd(nameof(helloworld).AsSpan());
|
||||
string dotnetCommunityToolkit = pool.GetOrAdd(nameof(dotnetCommunityToolkit).AsSpan());
|
||||
|
||||
Assert.AreEqual(nameof(hello), hello);
|
||||
Assert.AreEqual(nameof(helloworld), helloworld);
|
||||
Assert.AreEqual(nameof(windowsCommunityToolkit), windowsCommunityToolkit);
|
||||
Assert.AreEqual(nameof(dotnetCommunityToolkit), dotnetCommunityToolkit);
|
||||
|
||||
Assert.AreSame(hello, pool.GetOrAdd(hello.AsSpan()));
|
||||
Assert.AreSame(helloworld, pool.GetOrAdd(helloworld.AsSpan()));
|
||||
Assert.AreSame(windowsCommunityToolkit, pool.GetOrAdd(windowsCommunityToolkit.AsSpan()));
|
||||
Assert.AreSame(dotnetCommunityToolkit, pool.GetOrAdd(dotnetCommunityToolkit.AsSpan()));
|
||||
|
||||
pool.Reset();
|
||||
|
||||
Assert.AreEqual(nameof(hello), hello);
|
||||
Assert.AreEqual(nameof(helloworld), helloworld);
|
||||
Assert.AreEqual(nameof(windowsCommunityToolkit), windowsCommunityToolkit);
|
||||
Assert.AreEqual(nameof(dotnetCommunityToolkit), dotnetCommunityToolkit);
|
||||
|
||||
Assert.AreNotSame(hello, pool.GetOrAdd(hello.AsSpan()));
|
||||
Assert.AreNotSame(helloworld, pool.GetOrAdd(helloworld.AsSpan()));
|
||||
Assert.AreNotSame(windowsCommunityToolkit, pool.GetOrAdd(windowsCommunityToolkit.AsSpan()));
|
||||
Assert.AreNotSame(dotnetCommunityToolkit, pool.GetOrAdd(dotnetCommunityToolkit.AsSpan()));
|
||||
}
|
||||
|
||||
[TestCategory("StringPool")]
|
||||
|
@ -263,11 +261,10 @@ public class Test_StringPool
|
|||
|
||||
Span<byte> span2 = Encoding.ASCII.GetBytes(windowsCommunityToolkit);
|
||||
|
||||
string
|
||||
windowsCommunityToolkit2 = pool.GetOrAdd(span2, Encoding.ASCII),
|
||||
windowsCommunityToolkit3 = pool.GetOrAdd(windowsCommunityToolkit);
|
||||
string dotnetCommunityToolkit2 = pool.GetOrAdd(span2, Encoding.ASCII);
|
||||
string dotnetCommunityToolkit3 = pool.GetOrAdd(windowsCommunityToolkit);
|
||||
|
||||
Assert.AreSame(windowsCommunityToolkit2, windowsCommunityToolkit3);
|
||||
Assert.AreSame(dotnetCommunityToolkit2, dotnetCommunityToolkit3);
|
||||
}
|
||||
|
||||
[TestCategory("StringPool")]
|
||||
|
@ -318,9 +315,8 @@ public class Test_StringPool
|
|||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
int
|
||||
left = (i * 2) + 1,
|
||||
right = (i * 2) + 2;
|
||||
int left = (i * 2) + 1;
|
||||
int right = (i * 2) + 2;
|
||||
|
||||
if ((left < array.Length &&
|
||||
array[left] <= array[i]) ||
|
||||
|
|
|
@ -277,9 +277,8 @@ public partial class Test_ReadOnlySpanExtensions
|
|||
{
|
||||
int[,] array = new int[4, 5];
|
||||
|
||||
ReadOnlySpan<int>
|
||||
values1 = new[] { 10, 20, 30, 40, 50 },
|
||||
values2 = new[] { 11, 22, 33, 44, 55 };
|
||||
ReadOnlySpan<int> values1 = new[] { 10, 20, 30, 40, 50 };
|
||||
ReadOnlySpan<int> values2 = new[] { 11, 22, 33, 44, 55 };
|
||||
|
||||
// Copy a span to a target row and column with valid lengths
|
||||
values1.CopyTo(array.GetRow(0));
|
||||
|
@ -304,11 +303,11 @@ public partial class Test_ReadOnlySpanExtensions
|
|||
|
||||
result = new[,]
|
||||
{
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 10, 20, 30, 40, 50 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 10, 20, 30, 40, 50 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, result);
|
||||
}
|
||||
|
|
|
@ -175,9 +175,8 @@ public class Test_SpanExtensions
|
|||
{
|
||||
int[,] array = new int[4, 5];
|
||||
|
||||
int[]
|
||||
values1 = { 10, 20, 30, 40, 50 },
|
||||
values2 = { 11, 22, 33, 44, 55 };
|
||||
int[] values1 = { 10, 20, 30, 40, 50 };
|
||||
int[] values2 = { 11, 22, 33, 44, 55 };
|
||||
|
||||
// Copy a span to a target row and column with valid lengths
|
||||
values1.AsSpan().CopyTo(array.GetRow(0));
|
||||
|
@ -185,11 +184,11 @@ public class Test_SpanExtensions
|
|||
|
||||
int[,] result =
|
||||
{
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 0, 33, 0, 0, 0 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 0, 33, 0, 0, 0 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, result);
|
||||
|
||||
|
@ -202,11 +201,11 @@ public class Test_SpanExtensions
|
|||
|
||||
result = new[,]
|
||||
{
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 10, 20, 30, 40, 50 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
{ 10, 11, 30, 40, 50 },
|
||||
{ 0, 22, 0, 0, 0 },
|
||||
{ 10, 20, 30, 40, 50 },
|
||||
{ 0, 44, 0, 0, 0 }
|
||||
};
|
||||
|
||||
CollectionAssert.AreEqual(array, result);
|
||||
}
|
||||
|
|
|
@ -198,11 +198,10 @@ public class Test_BitHelper
|
|||
// Specific initial bit mask to check for unwanted modifications
|
||||
const uint value = 0xAAAA5555u;
|
||||
|
||||
uint
|
||||
backup = BitHelper.ExtractRange(value, start, length),
|
||||
result = BitHelper.SetRange(value, start, length, flags),
|
||||
extracted = BitHelper.ExtractRange(result, start, length),
|
||||
restored = BitHelper.SetRange(result, start, length, backup);
|
||||
uint backup = BitHelper.ExtractRange(value, start, length);
|
||||
uint result = BitHelper.SetRange(value, start, length, flags);
|
||||
uint extracted = BitHelper.ExtractRange(result, start, length);
|
||||
uint restored = BitHelper.SetRange(result, start, length, backup);
|
||||
|
||||
Assert.AreEqual(extracted, flags);
|
||||
Assert.AreEqual(restored, value);
|
||||
|
@ -312,11 +311,10 @@ public class Test_BitHelper
|
|||
// Specific initial bit mask to check for unwanted modifications
|
||||
const ulong value = 0xAAAA5555AAAA5555u;
|
||||
|
||||
ulong
|
||||
backup = BitHelper.ExtractRange(value, start, length),
|
||||
result = BitHelper.SetRange(value, start, length, flags),
|
||||
extracted = BitHelper.ExtractRange(result, start, length),
|
||||
restored = BitHelper.SetRange(result, start, length, backup);
|
||||
ulong backup = BitHelper.ExtractRange(value, start, length);
|
||||
ulong result = BitHelper.SetRange(value, start, length, flags);
|
||||
ulong extracted = BitHelper.ExtractRange(result, start, length);
|
||||
ulong restored = BitHelper.SetRange(result, start, length, backup);
|
||||
|
||||
Assert.AreEqual(extracted, flags);
|
||||
Assert.AreEqual(restored, value);
|
||||
|
|
|
@ -27,9 +27,8 @@ public partial class Test_ParallelHelper
|
|||
int height,
|
||||
int width)
|
||||
{
|
||||
int[,]
|
||||
data = CreateRandomData2D(sizeY, sizeX),
|
||||
copy = (int[,])data.Clone();
|
||||
int[,] data = CreateRandomData2D(sizeY, sizeX);
|
||||
int[,] copy = (int[,])data.Clone();
|
||||
|
||||
// Prepare the target data iteratively
|
||||
foreach (ref int n in copy.AsSpan2D(row, column, height, width))
|
||||
|
|
|
@ -507,7 +507,8 @@ public class Test_Memory2DT
|
|||
Memory2D<int> memory2d = new(array);
|
||||
|
||||
// Ensure that the GetHashCode method is repeatable
|
||||
int a = memory2d.GetHashCode(), b = memory2d.GetHashCode();
|
||||
int a = memory2d.GetHashCode();
|
||||
int b = memory2d.GetHashCode();
|
||||
|
||||
Assert.AreEqual(a, b);
|
||||
|
||||
|
|
|
@ -457,7 +457,8 @@ public class Test_ReadOnlyMemory2DT
|
|||
|
||||
ReadOnlyMemory2D<int> memory2d = new(array);
|
||||
|
||||
int a = memory2d.GetHashCode(), b = memory2d.GetHashCode();
|
||||
int a = memory2d.GetHashCode();
|
||||
int b = memory2d.GetHashCode();
|
||||
|
||||
Assert.AreEqual(a, b);
|
||||
|
||||
|
|
|
@ -82,9 +82,8 @@ public partial class Test_MemoryStream
|
|||
[TestMethod]
|
||||
public void Test_MemoryStream_WriteToEndAndRefreshPosition()
|
||||
{
|
||||
byte[]
|
||||
array = new byte[10],
|
||||
temp = new byte[1];
|
||||
byte[] array = new byte[10];
|
||||
byte[] temp = new byte[1];
|
||||
ReadOnlyMemory<byte> memory = array;
|
||||
|
||||
using Stream? stream = memory.AsStream();
|
||||
|
|
|
@ -211,14 +211,12 @@ public partial class Test_Messenger
|
|||
public void Test_Messenger_CollectionRequestMessage_Ok_MultipleReplies(Type type)
|
||||
{
|
||||
IMessenger? messenger = (IMessenger)Activator.CreateInstance(type)!;
|
||||
object
|
||||
recipient1 = new(),
|
||||
recipient2 = new(),
|
||||
recipient3 = new();
|
||||
object?
|
||||
r1 = null,
|
||||
r2 = null,
|
||||
r3 = null;
|
||||
object recipient1 = new();
|
||||
object recipient2 = new();
|
||||
object recipient3 = new();
|
||||
object? r1 = null;
|
||||
object? r2 = null;
|
||||
object? r3 = null;
|
||||
|
||||
void Receive1(object recipient, NumbersCollectionRequestMessage m)
|
||||
{
|
||||
|
@ -289,11 +287,10 @@ public partial class Test_Messenger
|
|||
public async Task Test_Messenger_AsyncCollectionRequestMessage_Ok_MultipleReplies(Type type)
|
||||
{
|
||||
IMessenger? messenger = (IMessenger)Activator.CreateInstance(type)!;
|
||||
object
|
||||
recipient1 = new(),
|
||||
recipient2 = new(),
|
||||
recipient3 = new(),
|
||||
recipient4 = new();
|
||||
object recipient1 = new();
|
||||
object recipient2 = new();
|
||||
object recipient3 = new();
|
||||
object recipient4 = new();
|
||||
|
||||
async Task<int> GetNumberAsync()
|
||||
{
|
||||
|
@ -329,11 +326,10 @@ public partial class Test_Messenger
|
|||
public async Task Test_Messenger_AsyncCollectionRequestMessage_Ok_MultipleReplies_Enumerate(Type type)
|
||||
{
|
||||
IMessenger? messenger = (IMessenger)Activator.CreateInstance(type)!;
|
||||
object
|
||||
recipient1 = new(),
|
||||
recipient2 = new(),
|
||||
recipient3 = new(),
|
||||
recipient4 = new();
|
||||
object recipient1 = new();
|
||||
object recipient2 = new();
|
||||
object recipient3 = new();
|
||||
object recipient4 = new();
|
||||
|
||||
async Task<int> GetNumberAsync()
|
||||
{
|
||||
|
|
|
@ -584,9 +584,8 @@ public class Test_ObservableValidator
|
|||
|
||||
protected override ValidationResult IsValid(object? value, ValidationContext validationContext)
|
||||
{
|
||||
object
|
||||
instance = validationContext.ObjectInstance,
|
||||
otherValue = instance.GetType().GetProperty(PropertyName)!.GetValue(instance)!;
|
||||
object instance = validationContext.ObjectInstance;
|
||||
object otherValue = instance.GetType().GetProperty(PropertyName)!.GetValue(instance)!;
|
||||
|
||||
if (((IComparable)value!).CompareTo(otherValue) > 0)
|
||||
{
|
||||
|
|
Загрузка…
Ссылка в новой задаче