Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ Add()

static void System.Text.RegularExpressions.RegexCache.Add ( Key key,
Regex regex )
inlinestaticprivate

Definition at line 162 of file RegexCache.cs.

163 {
164 lock (SyncObj)
165 {
166 if (s_maxCacheSize == 0 || s_cacheDictionary.TryGetValue(key, out var value))
167 {
168 return;
169 }
170 if (s_cacheList.Count == s_maxCacheSize)
171 {
172 int num;
173 bool flag;
174 if (s_maxCacheSize <= 30)
175 {
176 num = s_cacheList.Count;
177 flag = false;
178 }
179 else
180 {
181 num = 30;
182 flag = true;
183 }
184 int index = (flag ? s_random.Next(s_cacheList.Count) : 0);
185 long num2 = Volatile.Read(ref s_cacheList[index].LastAccessStamp);
186 for (int i = 1; i < num; i++)
187 {
188 int num3 = (flag ? s_random.Next(s_cacheList.Count) : i);
189 long num4 = Volatile.Read(ref s_cacheList[num3].LastAccessStamp);
190 if (num4 < num2)
191 {
192 index = num3;
193 num2 = num4;
194 }
195 }
197 s_cacheList.RemoveAt(index);
198 }
199 Node node = (s_lastAccessed = new Node(key, regex));
200 s_cacheList.Add(node);
201 s_cacheDictionary.TryAdd(key, node);
202 }
203 }
static readonly List< Node > s_cacheList
Definition RegexCache.cs:72
static readonly ConcurrentDictionary< Key, Node > s_cacheDictionary
Definition RegexCache.cs:70
static bool Read(ref bool location)
Definition Volatile.cs:67

References System.Text.RegularExpressions.i, System.index, System.key, System.Threading.Volatile.Read(), System.Text.RegularExpressions.RegexCache.s_cacheDictionary, System.Text.RegularExpressions.RegexCache.s_cacheList, System.Text.RegularExpressions.RegexCache.s_lastAccessed, System.Text.RegularExpressions.RegexCache.s_maxCacheSize, System.Text.RegularExpressions.RegexCache.s_random, System.Text.RegularExpressions.RegexCache.SyncObj, and System.Text.RegularExpressions.value.