Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
FastResourceComparer.cs
Go to the documentation of this file.
4
6
8{
9 internal static readonly FastResourceComparer Default = new FastResourceComparer();
10
11 public int GetHashCode(object key)
12 {
13 string key2 = (string)key;
14 return HashFunction(key2);
15 }
16
17 public int GetHashCode([DisallowNull] string key)
18 {
19 return HashFunction(key);
20 }
21
22 internal static int HashFunction(string key)
23 {
24 uint num = 5381u;
25 for (int i = 0; i < key.Length; i++)
26 {
27 num = ((num << 5) + num) ^ key[i];
28 }
29 return (int)num;
30 }
31
32 public int Compare(object a, object b)
33 {
34 if (a == b)
35 {
36 return 0;
37 }
38 string strA = (string)a;
39 string strB = (string)b;
40 return string.CompareOrdinal(strA, strB);
41 }
42
43 public int Compare(string a, string b)
44 {
45 return string.CompareOrdinal(a, b);
46 }
47
48 public bool Equals(string a, string b)
49 {
50 return string.Equals(a, b);
51 }
52
53 public new bool Equals(object a, object b)
54 {
55 if (a == b)
56 {
57 return true;
58 }
59 string a2 = (string)a;
60 string b2 = (string)b;
61 return string.Equals(a2, b2);
62 }
63
64 public unsafe static int CompareOrdinal(string a, byte[] bytes, int bCharLength)
65 {
66 int num = 0;
67 int num2 = 0;
68 int num3 = a.Length;
69 if (num3 > bCharLength)
70 {
72 }
73 if (bCharLength == 0)
74 {
75 if (a.Length != 0)
76 {
77 return -1;
78 }
79 return 0;
80 }
81 fixed (byte* ptr = bytes)
82 {
83 byte* ptr2 = ptr;
84 while (num < num3 && num2 == 0)
85 {
86 int num4 = *ptr2 | (ptr2[1] << 8);
87 num2 = a[num++] - num4;
88 ptr2 += 2;
89 }
90 }
91 if (num2 != 0)
92 {
93 return num2;
94 }
95 return a.Length - bCharLength;
96 }
97
98 public static int CompareOrdinal(byte[] bytes, int aCharLength, string b)
99 {
101 }
102
103 internal unsafe static int CompareOrdinal(byte* a, int byteLen, string b)
104 {
105 int num = 0;
106 int num2 = 0;
107 int num3 = byteLen >> 1;
108 if (num3 > b.Length)
109 {
110 num3 = b.Length;
111 }
112 while (num2 < num3 && num == 0)
113 {
114 char c = (char)(*(a++) | (*(a++) << 8));
115 num = c - b[num2++];
116 }
117 if (num != 0)
118 {
119 return num;
120 }
121 return byteLen - b.Length * 2;
122 }
123}
static int CompareOrdinal(byte[] bytes, int aCharLength, string b)
static unsafe int CompareOrdinal(string a, byte[] bytes, int bCharLength)
int GetHashCode([DisallowNull] string key)
static readonly FastResourceComparer Default
static unsafe int CompareOrdinal(byte *a, int byteLen, string b)