Skip to content

Commit 891e6e9

Browse files
committed
Optimize HotfixSettings for 25% perf gain when ParseAllHotfixes is disabled and no HotfixElement is enabled
1 parent eb7aebd commit 891e6e9

2 files changed

Lines changed: 24 additions & 20 deletions

File tree

WowPacketParser/Hotfix/HotfixConfiguration.cs

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Configuration;
34
using WowPacketParser.Enums;
45
using WowPacketParser.Misc;
@@ -10,33 +11,33 @@ public class HotfixSettings
1011
public static HotfixSettings Instance { get; } = new HotfixSettings();
1112

1213
private HotfixSection Section => (HotfixSection)ConfigurationManager.GetSection("Hotfix");
13-
private HotfixElementCollection Hashes => Section.FileHashes;
14+
private IReadOnlySet<string> _hashes;
15+
16+
public void LoadHashes()
17+
{
18+
var enabledTables = new HashSet<string>();
19+
20+
foreach (HotfixElement sectionFileHash in Section.FileHashes)
21+
if (sectionFileHash.Enabled)
22+
enabledTables.Add(sectionFileHash.FileHash);
23+
24+
_hashes = enabledTables;
25+
}
1426

1527
public bool ShouldLog(DB2Hash fileHash)
1628
{
17-
for (var i = 0; i < Hashes.Count; ++i)
18-
{
19-
if (Settings.ParseAllHotfixes == true)
20-
return true;
21-
22-
var currentElement = Hashes[i];
23-
if (currentElement.FileHash == fileHash.ToString())
24-
return currentElement.Enabled;
25-
}
26-
return false;
29+
if (Settings.ParseAllHotfixes)
30+
return true;
31+
32+
return _hashes.Contains(fileHash.ToString());
2733
}
2834

2935
public bool ShouldLog()
3036
{
31-
for (var i = 0; i < Hashes.Count; ++i)
32-
{
33-
if (Settings.ParseAllHotfixes == true)
34-
return true;
35-
36-
if (Hashes[i].Enabled)
37-
return true;
38-
}
39-
return false;
37+
if (Settings.ParseAllHotfixes)
38+
return true;
39+
40+
return _hashes.Count > 0;
4041
}
4142
}
4243

WowPacketParser/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.Reflection;
88
using System.Runtime.InteropServices;
99
using System.Threading;
10+
using WowPacketParser.Hotfix;
1011
using WowPacketParser.Loading;
1112
using WowPacketParser.Misc;
1213
using WowPacketParser.Parsing.Parsers;
@@ -79,6 +80,8 @@ private static void Main(string[] args)
7980

8081
SQLConnector.ReadDB();
8182

83+
HotfixSettings.Instance.LoadHashes();
84+
8285
List<Packets> parserPacketsList = new();
8386

8487
var processStartTime = DateTime.Now;

0 commit comments

Comments
 (0)