Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
AsyncLocalValueMap.cs
Go to the documentation of this file.
2
3namespace System.Threading;
4
5internal static class AsyncLocalValueMap
6{
8 {
10 {
12 {
13 return this;
14 }
16 }
17
18 public bool TryGetValue(IAsyncLocal key, out object value)
19 {
20 value = null;
21 return false;
22 }
23 }
24
26 {
27 private readonly IAsyncLocal _key1;
28
29 private readonly object _value1;
30
32 {
33 _key1 = key;
34 _value1 = value;
35 }
36
38 {
39 if (value != null || !treatNullValueAsNonexistent)
40 {
41 if (key != _key1)
42 {
44 }
46 }
47 if (key != _key1)
48 {
49 return this;
50 }
51 return Empty;
52 }
53
54 public bool TryGetValue(IAsyncLocal key, out object value)
55 {
56 if (key == _key1)
57 {
58 value = _value1;
59 return true;
60 }
61 value = null;
62 return false;
63 }
64 }
65
67 {
68 private readonly IAsyncLocal _key1;
69
70 private readonly IAsyncLocal _key2;
71
72 private readonly object _value1;
73
74 private readonly object _value2;
75
83
85 {
86 if (value != null || !treatNullValueAsNonexistent)
87 {
88 if (key != _key1)
89 {
90 if (key != _key2)
91 {
93 }
95 }
97 }
98 if (key != _key1)
99 {
100 if (key != _key2)
101 {
102 return this;
103 }
105 }
107 }
108
109 public bool TryGetValue(IAsyncLocal key, out object value)
110 {
111 if (key == _key1)
112 {
113 value = _value1;
114 return true;
115 }
116 if (key == _key2)
117 {
118 value = _value2;
119 return true;
120 }
121 value = null;
122 return false;
123 }
124 }
125
127 {
128 private readonly IAsyncLocal _key1;
129
130 private readonly IAsyncLocal _key2;
131
132 private readonly IAsyncLocal _key3;
133
134 private readonly object _value1;
135
136 private readonly object _value2;
137
138 private readonly object _value3;
139
141 {
142 _key1 = key1;
143 _value1 = value1;
144 _key2 = key2;
145 _value2 = value2;
146 _key3 = key3;
147 _value3 = value3;
148 }
149
151 {
152 if (value != null || !treatNullValueAsNonexistent)
153 {
154 if (key == _key1)
155 {
157 }
158 if (key == _key2)
159 {
161 }
162 if (key == _key3)
163 {
165 }
172 }
173 if (key != _key1)
174 {
175 if (key != _key2)
176 {
177 if (key != _key3)
178 {
179 return this;
180 }
182 }
184 }
186 }
187
188 public bool TryGetValue(IAsyncLocal key, out object value)
189 {
190 if (key == _key1)
191 {
192 value = _value1;
193 return true;
194 }
195 if (key == _key2)
196 {
197 value = _value2;
198 return true;
199 }
200 if (key == _key3)
201 {
202 value = _value3;
203 return true;
204 }
205 value = null;
206 return false;
207 }
208 }
209
211 {
213
218
219 internal void UnsafeStore(int index, IAsyncLocal key, object value)
220 {
222 }
223
225 {
226 for (int i = 0; i < _keyValues.Length; i++)
227 {
228 if (key == _keyValues[i].Key)
229 {
230 if (value != null || !treatNullValueAsNonexistent)
231 {
236 }
237 if (_keyValues.Length == 4)
238 {
239 return i switch
240 {
241 2 => new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[3].Key, _keyValues[3].Value),
242 1 => new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value),
243 0 => new ThreeElementAsyncLocalValueMap(_keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value, _keyValues[3].Key, _keyValues[3].Value),
244 _ => new ThreeElementAsyncLocalValueMap(_keyValues[0].Key, _keyValues[0].Value, _keyValues[1].Key, _keyValues[1].Value, _keyValues[2].Key, _keyValues[2].Value),
245 };
246 }
248 if (i != 0)
249 {
251 }
252 if (i != _keyValues.Length - 1)
253 {
254 Array.Copy(_keyValues, i + 1, multiElementAsyncLocalValueMap2._keyValues, i, _keyValues.Length - i - 1);
255 }
257 }
258 }
259 if (value == null && treatNullValueAsNonexistent)
260 {
261 return this;
262 }
263 if (_keyValues.Length < 16)
264 {
269 }
272 for (int j = 0; j < keyValues.Length; j++)
273 {
276 }
279 }
280
281 public bool TryGetValue(IAsyncLocal key, out object value)
282 {
284 for (int i = 0; i < keyValues.Length; i++)
285 {
287 if (key == keyValuePair.Key)
288 {
289 value = keyValuePair.Value;
290 return true;
291 }
292 }
293 value = null;
294 return false;
295 }
296 }
297
298 private sealed class ManyElementAsyncLocalValueMap : Dictionary<IAsyncLocal, object>, IAsyncLocalValueMap
299 {
301 : base(capacity)
302 {
303 }
304
306 {
307 int count = base.Count;
308 bool flag = ContainsKey(key);
309 if (value != null || !treatNullValueAsNonexistent)
310 {
312 using (Enumerator enumerator = GetEnumerator())
313 {
314 while (enumerator.MoveNext())
315 {
317 manyElementAsyncLocalValueMap[current.Key] = current.Value;
318 }
319 }
322 }
323 if (flag)
324 {
325 if (count == 17)
326 {
328 int num = 0;
329 using Enumerator enumerator2 = GetEnumerator();
330 while (enumerator2.MoveNext())
331 {
333 if (key != current2.Key)
334 {
335 multiElementAsyncLocalValueMap.UnsafeStore(num++, current2.Key, current2.Value);
336 }
337 }
339 }
341 using Enumerator enumerator3 = GetEnumerator();
342 while (enumerator3.MoveNext())
343 {
345 if (key != current3.Key)
346 {
348 }
349 }
351 }
352 return this;
353 }
354 }
355
356 public static IAsyncLocalValueMap Empty { get; } = new EmptyAsyncLocalValueMap();
357
358
360 {
361 return asyncLocalValueMap == Empty;
362 }
363
365 {
366 if (value == null && treatNullValueAsNonexistent)
367 {
368 return Empty;
369 }
371 }
372}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
readonly KeyValuePair< IAsyncLocal, object >[] _keyValues
void UnsafeStore(int index, IAsyncLocal key, object value)
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
ThreeElementAsyncLocalValueMap(IAsyncLocal key1, object value1, IAsyncLocal key2, object value2, IAsyncLocal key3, object value3)
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
IAsyncLocalValueMap Set(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)
TwoElementAsyncLocalValueMap(IAsyncLocal key1, object value1, IAsyncLocal key2, object value2)
static bool IsEmpty(IAsyncLocalValueMap asyncLocalValueMap)
static IAsyncLocalValueMap Create(IAsyncLocal key, object value, bool treatNullValueAsNonexistent)