This is not a particularly common pattern, but it is a missed optimization all the same.
Consider:
public static int Array_NE(byte[] src)
{
int sum = 0;
for (int i = 0; i != src.Length; i++)
sum += src[i];
return sum;
}
public static int Array_LT(byte[] src)
{
int sum = 0;
for (int i = 0; i < src.Length; i++)
sum += src[i];
return sum;
}
A bounds check is eliminated for the second method but not the first.
Applies to T[], string, Span<T>, ReadOnlySpan<T>, etc.
https://csharp.godbolt.org/z/bKzrE9Wjq
This is not a particularly common pattern, but it is a missed optimization all the same.
Consider:
A bounds check is eliminated for the second method but not the first.
Applies to
T[],string,Span<T>,ReadOnlySpan<T>, etc.https://csharp.godbolt.org/z/bKzrE9Wjq