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

◆ LastIndexOfAny() [2/2]

static int System.SpanHelpers.LastIndexOfAny ( ref byte searchSpace,
byte value0,
byte value1,
int length )
inlinestatic

Definition at line 933 of file SpanHelpers.cs.

934 {
935 nuint num = (uint)length;
936 nuint num2 = (uint)length;
938 {
940 }
941 while (true)
942 {
943 if (num2 >= 8)
944 {
945 num2 -= 8;
946 num -= 8;
947 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num + 7);
948 if (value0 == num3 || value1 == num3)
949 {
950 break;
951 }
952 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 6);
953 if (value0 != num3 && value1 != num3)
954 {
955 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 5);
956 if (value0 != num3 && value1 != num3)
957 {
958 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 4);
959 if (value0 != num3 && value1 != num3)
960 {
961 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
962 if (value0 != num3 && value1 != num3)
963 {
964 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
965 if (value0 != num3 && value1 != num3)
966 {
967 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
968 if (value0 != num3 && value1 != num3)
969 {
970 num3 = Unsafe.AddByteOffset(ref searchSpace, num);
971 if (value0 != num3 && value1 != num3)
972 {
973 continue;
974 }
975 goto IL_027c;
976 }
977 goto IL_027f;
978 }
979 goto IL_0285;
980 }
981 goto IL_028b;
982 }
983 return (int)(num + 4);
984 }
985 return (int)(num + 5);
986 }
987 return (int)(num + 6);
988 }
989 if (num2 >= 4)
990 {
991 num2 -= 4;
992 num -= 4;
993 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num + 3);
994 if (value0 == num3 || value1 == num3)
995 {
996 goto IL_028b;
997 }
998 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 2);
999 if (value0 == num3 || value1 == num3)
1000 {
1001 goto IL_0285;
1002 }
1003 num3 = Unsafe.AddByteOffset(ref searchSpace, num + 1);
1004 if (value0 == num3 || value1 == num3)
1005 {
1006 goto IL_027f;
1007 }
1008 num3 = Unsafe.AddByteOffset(ref searchSpace, num);
1009 if (value0 == num3 || value1 == num3)
1010 {
1011 goto IL_027c;
1012 }
1013 }
1014 while (num2 != 0)
1015 {
1016 num2--;
1017 num--;
1018 uint num3 = Unsafe.AddByteOffset(ref searchSpace, num);
1019 if (value0 != num3 && value1 != num3)
1020 {
1021 continue;
1022 }
1023 goto IL_027c;
1024 }
1025 if (Vector.IsHardwareAccelerated && num != 0)
1026 {
1027 num2 = num & (nuint)(~(Vector<byte>.Count - 1));
1028 Vector<byte> right = new Vector<byte>(value0);
1030 while (num2 > (nuint)(Vector<byte>.Count - 1))
1031 {
1032 Vector<byte> left = LoadVector(ref searchSpace, num - (nuint)Vector<byte>.Count);
1033 Vector<byte> vector = Vector.BitwiseOr(Vector.Equals(left, right), Vector.Equals(left, right2));
1034 if (Vector<byte>.Zero.Equals(vector))
1035 {
1036 num -= (nuint)Vector<byte>.Count;
1037 num2 -= (nuint)Vector<byte>.Count;
1038 continue;
1039 }
1040 return (int)num - Vector<byte>.Count + LocateLastFoundByte(vector);
1041 }
1042 if (num != 0)
1043 {
1044 num2 = num;
1045 continue;
1046 }
1047 }
1048 return -1;
1049 IL_027c:
1050 return (int)num;
1051 IL_028b:
1052 return (int)(num + 3);
1053 IL_027f:
1054 return (int)(num + 1);
1055 IL_0285:
1056 return (int)(num + 2);
1057 }
1058 return (int)(num + 7);
1059 }
static bool IsHardwareAccelerated
Definition Vector.cs:14
static Vector< int > Equals(Vector< float > left, Vector< float > right)
Definition Vector.cs:52
static Vector< byte > LoadVector(ref byte start, nuint offset)
static int LocateLastFoundByte(Vector< byte > match)
static unsafe nuint UnalignedCountVectorFromEnd(ref byte searchSpace, int length)

References System.Collections.Generic.Dictionary< TKey, TValue >.Count, System.Numerics.Vector< T >.Equals(), System.Numerics.Vector< T >.IsHardwareAccelerated, System.length, System.SpanHelpers.LoadVector(), System.SpanHelpers.LocateLastFoundByte(), and System.SpanHelpers.UnalignedCountVectorFromEnd().

Referenced by System.MemoryExtensions.LastIndexOfAny< T >(), System.MemoryExtensions.LastIndexOfAny< T >(), System.MemoryExtensions.LastIndexOfAny< T >(), System.MemoryExtensions.LastIndexOfAny< T >(), System.MemoryExtensions.LastIndexOfAny< T >(), and System.MemoryExtensions.LastIndexOfAny< T >().