Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CaseInsensitiveAscii.cs
Go to the documentation of this file.
2
3namespace System.Net;
4
5internal sealed class CaseInsensitiveAscii : IEqualityComparer, IComparer
6{
8
9 internal static ReadOnlySpan<byte> AsciiToLower => new byte[256]
10 {
11 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
12 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
13 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
14 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
15 40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
16 50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
17 60, 61, 62, 63, 64, 97, 98, 99, 100, 101,
18 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
19 112, 113, 114, 115, 116, 117, 118, 119, 120, 121,
20 122, 91, 92, 93, 94, 95, 96, 97, 98, 99,
21 100, 101, 102, 103, 104, 105, 106, 107, 108, 109,
22 110, 111, 112, 113, 114, 115, 116, 117, 118, 119,
23 120, 121, 122, 123, 124, 125, 126, 127, 128, 129,
24 130, 131, 132, 133, 134, 135, 136, 137, 138, 139,
25 140, 141, 142, 143, 144, 145, 146, 147, 148, 149,
26 150, 151, 152, 153, 154, 155, 156, 157, 158, 159,
27 160, 161, 162, 163, 164, 165, 166, 167, 168, 169,
28 170, 171, 172, 173, 174, 175, 176, 177, 178, 179,
29 180, 181, 182, 183, 184, 185, 186, 187, 188, 189,
30 190, 191, 192, 193, 194, 195, 196, 197, 198, 199,
31 200, 201, 202, 203, 204, 205, 206, 207, 208, 209,
32 210, 211, 212, 213, 214, 215, 216, 217, 218, 219,
33 220, 221, 222, 223, 224, 225, 226, 227, 228, 229,
34 230, 231, 232, 233, 234, 235, 236, 237, 238, 239,
35 240, 241, 242, 243, 244, 245, 246, 247, 248, 249,
36 250, 251, 252, 253, 254, 255
37 };
38
39 public int GetHashCode(object myObject)
40 {
41 if (!(myObject is string { Length: var length } text))
42 {
43 return 0;
44 }
45 if (length == 0)
46 {
47 return 0;
48 }
49 return length ^ ((AsciiToLower[(byte)text[0]] << 24) ^ (AsciiToLower[(byte)text[length - 1]] << 16));
50 }
51
52 public int Compare(object firstObject, object secondObject)
53 {
54 string text = firstObject as string;
55 string text2 = secondObject as string;
56 if (text == null)
57 {
58 if (text2 != null)
59 {
60 return -1;
61 }
62 return 0;
63 }
64 if (text2 == null)
65 {
66 return 1;
67 }
68 int num = text.Length - text2.Length;
69 int num2 = ((num > 0) ? text2.Length : text.Length);
70 for (int i = 0; i < num2; i++)
71 {
72 int num3 = AsciiToLower[text[i]] - AsciiToLower[text2[i]];
73 if (num3 != 0)
74 {
75 num = num3;
76 break;
77 }
78 }
79 return num;
80 }
81
82 private int FastGetHashCode(string myString)
83 {
84 int num = myString.Length;
85 if (num != 0)
86 {
87 num ^= (AsciiToLower[(byte)myString[0]] << 24) ^ (AsciiToLower[(byte)myString[num - 1]] << 16);
88 }
89 return num;
90 }
91
92 public new bool Equals(object firstObject, object secondObject)
93 {
94 string text = firstObject as string;
95 string text2 = secondObject as string;
96 if (text == null)
97 {
98 return text2 == null;
99 }
100 if (text2 != null)
101 {
102 int num = text.Length;
103 if (num == text2.Length && FastGetHashCode(text) == FastGetHashCode(text2))
104 {
105 while (num > 0)
106 {
107 num--;
108 if (AsciiToLower[text[num]] != AsciiToLower[text2[num]])
109 {
110 return false;
111 }
112 }
113 return true;
114 }
115 }
116 return false;
117 }
118}
static readonly CaseInsensitiveAscii StaticInstance
new bool Equals(object firstObject, object secondObject)
static ReadOnlySpan< byte > AsciiToLower
int Compare(object firstObject, object secondObject)