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;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Windows.Forms;
using Dalamud.IoC; using Dalamud.IoC;
using Dalamud.IoC.Internal; using Dalamud.IoC.Internal;
using Dalamud.Utility.Timing; using Dalamud.Utility.Timing;
@ -27,7 +28,7 @@ namespace Dalamud.Game
private IntPtr moduleCopyPtr; private IntPtr moduleCopyPtr;
private long moduleCopyOffset; private long moduleCopyOffset;
private Dictionary<string, long>? textCache; private ConcurrentDictionary<string, long>? textCache;
[ServiceManager.ServiceConstructor] [ServiceManager.ServiceConstructor]
private SigScanner(DalamudStartInfo startInfo) private SigScanner(DalamudStartInfo startInfo)
@ -342,12 +343,9 @@ namespace Dalamud.Game
{ {
if (this.textCache != null) if (this.textCache != null)
{ {
lock (this.textCache) if (this.textCache.TryGetValue(signature, out var address))
{ {
if (this.textCache.TryGetValue(signature, out var address)) return new IntPtr(address + this.Module.BaseAddress.ToInt64());
{
return new IntPtr(address + this.Module.BaseAddress.ToInt64());
}
} }
} }
@ -364,10 +362,7 @@ namespace Dalamud.Game
if (this.textCache != null) if (this.textCache != null)
{ {
lock (this.textCache) this.textCache[signature] = scanRet.ToInt64() - this.Module.BaseAddress.ToInt64();
{
this.textCache[signature] = scanRet.ToInt64() - this.Module.BaseAddress.ToInt64();
}
} }
return scanRet; return scanRet;
@ -563,7 +558,7 @@ namespace Dalamud.Game
return; 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>();
} }
} }
} }