From 7dc61e76ab2b736b5f616f58fa74f497e1d8c6c9 Mon Sep 17 00:00:00 2001 From: "Michael J. Seiferling" Date: Mon, 12 Nov 2018 11:59:07 -0600 Subject: [PATCH] Store compiled regular expressions for #170 --- GBM/Classes/clsGame.vb | 14 +++++++++++++- GBM/Managers/mgrMonitorList.vb | 5 +++++ GBM/Managers/mgrProcessDetection.vb | 5 +---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/GBM/Classes/clsGame.vb b/GBM/Classes/clsGame.vb index ea1447d..6a1fb97 100644 --- a/GBM/Classes/clsGame.vb +++ b/GBM/Classes/clsGame.vb @@ -1,4 +1,6 @@ - +Imports System.Text.RegularExpressions + + Public Class clsGame Private sGameID As String = Guid.NewGuid.ToString Private sGameName As String = String.Empty @@ -24,6 +26,7 @@ Public Class clsGame Private bRecurseSubFolders As Boolean = True Private oImportTags As New List(Of Tag) Private bImportUpdate As Boolean = False + Private oCompiledRegEx As Regex Public Enum eOptionalSyncFields None = 0 @@ -278,6 +281,15 @@ Public Class clsGame End Set End Property + Property CompiledRegEx As Regex + Get + Return oCompiledRegEx + End Get + Set(value As Regex) + oCompiledRegEx = value + End Set + End Property + ReadOnly Property IncludeArray As String() Get If FileType = String.Empty Then diff --git a/GBM/Managers/mgrMonitorList.vb b/GBM/Managers/mgrMonitorList.vb index 1112f19..d977501 100644 --- a/GBM/Managers/mgrMonitorList.vb +++ b/GBM/Managers/mgrMonitorList.vb @@ -38,6 +38,11 @@ Public Class mgrMonitorList oGame.IsRegEx = CBool(dr("IsRegEx")) oGame.RecurseSubFolders = CBool(dr("RecurseSubFolders")) + 'Compile RegEx + If oGame.IsRegEx Then + oGame.CompiledRegEx = New Regex(oGame.ProcessName, RegexOptions.Compiled) + End If + Return oGame End Function diff --git a/GBM/Managers/mgrProcessDetection.vb b/GBM/Managers/mgrProcessDetection.vb index 9fda12d..0aa19ce 100644 --- a/GBM/Managers/mgrProcessDetection.vb +++ b/GBM/Managers/mgrProcessDetection.vb @@ -1,6 +1,5 @@ Imports System.IO Imports System.Management -Imports System.Text.RegularExpressions Public Class mgrProcessDetection @@ -12,7 +11,6 @@ Public Class mgrProcessDetection Private oDuplicateGames As New ArrayList Private bDuplicates As Boolean Private bVerified As Boolean = False - Private oRegEx As Regex Property FoundProcess As Process Get @@ -144,8 +142,7 @@ Public Class mgrProcessDetection Private Function IsMatch(ByRef oGame As clsGame, ByRef sProcessCheck As String) As Boolean If oGame.IsRegEx Then Try - oRegEx = New Regex(oGame.ProcessName) - If oRegEx.IsMatch(sProcessCheck) Then + If oGame.CompiledRegEx.IsMatch(sProcessCheck) Then Return True End If Catch