Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
RuleCache.cs
Go to the documentation of this file.
4
6
7[EditorBrowsable(EditorBrowsableState.Never)]
8[DebuggerStepThrough]
9public class RuleCache<T> where T : class
10{
11 private T[] _rules = Array.Empty<T>();
12
13 private readonly object _cacheLock = new object();
14
15 internal RuleCache()
16 {
17 }
18
19 internal T[] GetRules()
20 {
21 return _rules;
22 }
23
24 internal void MoveRule(T rule, int i)
25 {
26 lock (_cacheLock)
27 {
28 int num = _rules.Length - i;
29 if (num > 8)
30 {
31 num = 8;
32 }
33 int num2 = -1;
34 int num3 = Math.Min(_rules.Length, i + num);
35 for (int j = i; j < num3; j++)
36 {
37 if (_rules[j] == rule)
38 {
39 num2 = j;
40 break;
41 }
42 }
43 if (num2 >= 2)
44 {
45 T val = _rules[num2];
46 _rules[num2] = _rules[num2 - 1];
47 _rules[num2 - 1] = _rules[num2 - 2];
48 _rules[num2 - 2] = val;
49 }
50 }
51 }
52
53 internal void AddRule(T newRule)
54 {
55 lock (_cacheLock)
56 {
57 _rules = AddOrInsert(_rules, newRule);
58 }
59 }
60
61 private static T[] AddOrInsert(T[] rules, T item)
62 {
63 if (rules.Length < 64)
64 {
65 return rules.AddLast(item);
66 }
67 int num = rules.Length + 1;
68 T[] array;
69 if (num > 128)
70 {
71 num = 128;
72 array = rules;
73 }
74 else
75 {
76 array = new T[num];
77 Array.Copy(rules, array, 64);
78 }
79 array[64] = item;
80 Array.Copy(rules, 64, array, 65, num - 64 - 1);
81 return array;
82 }
83}
static unsafe void Copy(Array sourceArray, Array destinationArray, int length)
Definition Array.cs:624
static byte Min(byte val1, byte val2)
Definition Math.cs:912
static T[] AddOrInsert(T[] rules, T item)
Definition RuleCache.cs:61