Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ LastIndexOf< T >() [3/3]

static int System.Array.LastIndexOf< T > ( T[] array,
T value,
int startIndex,
int count )
inlinestatic

Definition at line 2151 of file Array.cs.

2152 {
2153 if (array == null)
2154 {
2155 ThrowHelper.ThrowArgumentNullException(ExceptionArgument.array);
2156 }
2157 if (array.Length == 0)
2158 {
2159 if (startIndex != -1 && startIndex != 0)
2160 {
2161 ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
2162 }
2163 if (count != 0)
2164 {
2165 ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
2166 }
2167 return -1;
2168 }
2169 if ((uint)startIndex >= (uint)array.Length)
2170 {
2171 ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index();
2172 }
2173 if (count < 0 || startIndex - count + 1 < 0)
2174 {
2175 ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count();
2176 }
2177 if (RuntimeHelpers.IsBitwiseEquatable<T>())
2178 {
2179 if (Unsafe.SizeOf<T>() == 1)
2180 {
2181 int num = startIndex - count + 1;
2182 int num2 = SpanHelpers.LastIndexOf(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<byte[]>(array)), num), Unsafe.As<T, byte>(ref value), count);
2183 return ((num2 >= 0) ? num : 0) + num2;
2184 }
2185 if (Unsafe.SizeOf<T>() == 2)
2186 {
2187 int num3 = startIndex - count + 1;
2188 int num4 = SpanHelpers.LastIndexOf(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<char[]>(array)), num3), Unsafe.As<T, char>(ref value), count);
2189 return ((num4 >= 0) ? num3 : 0) + num4;
2190 }
2191 if (Unsafe.SizeOf<T>() == 4)
2192 {
2193 int num5 = startIndex - count + 1;
2194 int num6 = SpanHelpers.LastIndexOf(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<int[]>(array)), num5), Unsafe.As<T, int>(ref value), count);
2195 return ((num6 >= 0) ? num5 : 0) + num6;
2196 }
2197 if (Unsafe.SizeOf<T>() == 8)
2198 {
2199 int num7 = startIndex - count + 1;
2200 int num8 = SpanHelpers.LastIndexOf(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(Unsafe.As<long[]>(array)), num7), Unsafe.As<T, long>(ref value), count);
2201 return ((num8 >= 0) ? num7 : 0) + num8;
2202 }
2203 }
2204 return EqualityComparer<T>.Default.LastIndexOf(array, value, startIndex, count);
2205 }
static unsafe ref byte GetArrayDataReference(Array array)

References System.array, System.count, System.Runtime.InteropServices.MemoryMarshal.GetArrayDataReference(), System.SpanHelpers.LastIndexOf(), System.startIndex, System.T, System.ThrowHelper.ThrowArgumentNullException(), System.ThrowHelper.ThrowCountArgumentOutOfRange_ArgumentOutOfRange_Count(), System.ThrowHelper.ThrowStartIndexArgumentOutOfRange_ArgumentOutOfRange_Index(), and System.value.