mscorlib(4.0.0.0) API with additions
RuleCache.cs
2 using System.Diagnostics;
3 using System.Dynamic.Utils;
4 
6 {
9  [EditorBrowsable(EditorBrowsableState.Never)]
10  [DebuggerStepThrough]
11  [global::__DynamicallyInvokable]
12  public class RuleCache<T> where T : class
13  {
14  private T[] _rules = new T[0];
15 
16  private readonly object cacheLock = new object();
17 
18  private const int MaxRules = 128;
19 
20  private const int InsertPosition = 64;
21 
22  internal RuleCache()
23  {
24  }
25 
26  internal T[] GetRules()
27  {
28  return _rules;
29  }
30 
31  internal void MoveRule(T rule, int i)
32  {
33  lock (cacheLock)
34  {
35  int num = _rules.Length - i;
36  if (num > 8)
37  {
38  num = 8;
39  }
40  int num2 = -1;
41  int num3 = Math.Min(_rules.Length, i + num);
42  for (int j = i; j < num3; j++)
43  {
44  if (_rules[j] == rule)
45  {
46  num2 = j;
47  break;
48  }
49  }
50  if (num2 >= 0)
51  {
52  T val = _rules[num2];
53  _rules[num2] = _rules[num2 - 1];
54  _rules[num2 - 1] = _rules[num2 - 2];
55  _rules[num2 - 2] = val;
56  }
57  }
58  }
59 
60  internal void AddRule(T newRule)
61  {
62  lock (cacheLock)
63  {
64  _rules = AddOrInsert(_rules, newRule);
65  }
66  }
67 
68  internal void ReplaceRule(T oldRule, T newRule)
69  {
70  lock (cacheLock)
71  {
72  int num = Array.IndexOf(_rules, oldRule);
73  if (num >= 0)
74  {
75  _rules[num] = newRule;
76  }
77  else
78  {
79  _rules = AddOrInsert(_rules, newRule);
80  }
81  }
82  }
83 
84  private static T[] AddOrInsert(T[] rules, T item)
85  {
86  if (rules.Length < 64)
87  {
88  return rules.AddLast(item);
89  }
90  int num = rules.Length + 1;
91  T[] array;
92  if (num > 128)
93  {
94  num = 128;
95  array = rules;
96  }
97  else
98  {
99  array = new T[num];
100  }
101  Array.Copy(rules, 0, array, 0, 64);
102  array[64] = item;
103  Array.Copy(rules, 64, array, 65, num - 64 - 1);
104  return array;
105  }
106  }
107 }
Represents a cache of runtime binding rules.
Definition: RuleCache.cs:12
EditorBrowsableState
Specifies the browsable state of a property or method from within an editor.
static sbyte Min(sbyte val1, sbyte val2)
Returns the smaller of two 8-bit signed integers.
Definition: Math.cs:762
Definition: __Canon.cs:3
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Definition: Array.cs:17
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
Definition: Array.cs:1275
Provides constants and static methods for trigonometric, logarithmic, and other common mathematical f...
Definition: Math.cs:10