chore: use ConcurrentDictionary in SigScanner

This commit is contained in:
goaaats 2022-06-25 14:17:57 +02:00
parent 7760457dc5
commit cf13e4f69d
No known key found for this signature in database
GPG key ID: 49E2AA8C6A76498B

View file

@ -1,11 +1,12 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows.Forms;
using Dalamud.IoC;
using Dalamud.IoC.Internal;
using Dalamud.Utility.Timing;
@ -27,7 +28,7 @@ namespace Dalamud.Game
private IntPtr moduleCopyPtr;
private long moduleCopyOffset;
private Dictionary<string, long>? textCache;
private ConcurrentDictionary<string, long>? textCache;
[ServiceManager.ServiceConstructor]
private SigScanner(DalamudStartInfo startInfo)
@ -341,15 +342,12 @@ namespace Dalamud.Game
public IntPtr ScanText(string signature)
{
if (this.textCache != null)
{
lock (this.textCache)
{
if (this.textCache.TryGetValue(signature, out var address))
{
return new IntPtr(address + this.Module.BaseAddress.ToInt64());
}
}
}
var mBase = this.IsCopy ? this.moduleCopyPtr : this.TextSectionBase;
var scanRet = Scan(mBase, this.TextSectionSize, signature);
@ -363,12 +361,9 @@ namespace Dalamud.Game
scanRet = ReadJmpCallSig(scanRet);
if (this.textCache != null)
{
lock (this.textCache)
{
this.textCache[signature] = scanRet.ToInt64() - this.Module.BaseAddress.ToInt64();
}
}
return scanRet;
}
@ -563,7 +558,7 @@ namespace Dalamud.Game
return;
}
this.textCache = JsonConvert.DeserializeObject<Dictionary<string, long>>(File.ReadAllText(this.cacheFile.FullName)) ?? new Dictionary<string, long>();
this.textCache = JsonConvert.DeserializeObject<ConcurrentDictionary<string, long>>(File.ReadAllText(this.cacheFile.FullName)) ?? new ConcurrentDictionary<string, long>();
}
}
}