Files
2026-06-04 11:42:34 +02:00

126 lines
3.0 KiB
C#

using System;
using System.Collections;
namespace System.Text.RegularExpressions
{
// Token: 0x020002BF RID: 703
internal class FactoryCache
{
// Token: 0x0600199E RID: 6558 RVA: 0x0005B1C0 File Offset: 0x000593C0
public FactoryCache(int capacity)
{
this.capacity = capacity;
this.factories = new Hashtable(capacity);
this.mru_list = new MRUList();
}
// Token: 0x0600199F RID: 6559 RVA: 0x0005B1F4 File Offset: 0x000593F4
public void Add(string pattern, RegexOptions options, IMachineFactory factory)
{
lock (this)
{
FactoryCache.Key key = new FactoryCache.Key(pattern, options);
this.Cleanup();
this.factories[key] = factory;
this.mru_list.Use(key);
}
}
// Token: 0x060019A0 RID: 6560 RVA: 0x0005B258 File Offset: 0x00059458
private void Cleanup()
{
while (this.factories.Count >= this.capacity && this.capacity > 0)
{
object obj = this.mru_list.Evict();
if (obj != null)
{
this.factories.Remove((FactoryCache.Key)obj);
}
}
}
// Token: 0x060019A1 RID: 6561 RVA: 0x0005B2B0 File Offset: 0x000594B0
public IMachineFactory Lookup(string pattern, RegexOptions options)
{
lock (this)
{
FactoryCache.Key key = new FactoryCache.Key(pattern, options);
if (this.factories.Contains(key))
{
this.mru_list.Use(key);
return (IMachineFactory)this.factories[key];
}
}
return null;
}
// Token: 0x17000800 RID: 2048
// (get) Token: 0x060019A2 RID: 6562 RVA: 0x0005B32C File Offset: 0x0005952C
// (set) Token: 0x060019A3 RID: 6563 RVA: 0x0005B334 File Offset: 0x00059534
public int Capacity
{
get
{
return this.capacity;
}
set
{
lock (this)
{
this.capacity = value;
this.Cleanup();
}
}
}
// Token: 0x040014D4 RID: 5332
private int capacity;
// Token: 0x040014D5 RID: 5333
private Hashtable factories;
// Token: 0x040014D6 RID: 5334
private MRUList mru_list;
// Token: 0x020002C0 RID: 704
private class Key
{
// Token: 0x060019A4 RID: 6564 RVA: 0x0005B380 File Offset: 0x00059580
public Key(string pattern, RegexOptions options)
{
this.pattern = pattern;
this.options = options;
}
// Token: 0x060019A5 RID: 6565 RVA: 0x0005B398 File Offset: 0x00059598
public override int GetHashCode()
{
return this.pattern.GetHashCode() ^ (int)this.options;
}
// Token: 0x060019A6 RID: 6566 RVA: 0x0005B3AC File Offset: 0x000595AC
public override bool Equals(object o)
{
if (o == null || !(o is FactoryCache.Key))
{
return false;
}
FactoryCache.Key key = (FactoryCache.Key)o;
return this.options == key.options && this.pattern.Equals(key.pattern);
}
// Token: 0x060019A7 RID: 6567 RVA: 0x0005B3F8 File Offset: 0x000595F8
public override string ToString()
{
return string.Concat(new object[] { "('", this.pattern, "', [", this.options, "])" });
}
// Token: 0x040014D7 RID: 5335
public string pattern;
// Token: 0x040014D8 RID: 5336
public RegexOptions options;
}
}
}