From 975bc5d584185e44d6eee2b5e38f137d1f35d66d Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 5 Feb 2023 16:29:37 +0530 Subject: [PATCH] BlockListZoneManager: refactored code for optimization. --- DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs b/DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs index bc09a64f..022e8e4d 100644 --- a/DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs +++ b/DnsServerCore/Dns/ZoneManagers/BlockListZoneManager.cs @@ -35,6 +35,8 @@ namespace DnsServerCore.Dns.ZoneManagers { #region variables + readonly static char[] _popWordSeperator = new char[] { ' ', '\t' }; + readonly DnsServer _dnsServer; readonly string _localCacheFolder; @@ -87,9 +89,9 @@ namespace DnsServerCore.Dns.ZoneManagers if (line.Length == 0) return line; - line = line.TrimStart(' ', '\t'); + line = line.TrimStart(_popWordSeperator); - int i = line.IndexOfAny(new char[] { ' ', '\t' }); + int i = line.IndexOfAny(_popWordSeperator); string word; if (i < 0) @@ -120,6 +122,7 @@ namespace DnsServerCore.Dns.ZoneManagers { //parse hosts file and populate block zone StreamReader sR = new StreamReader(fS, true); + char[] trimSeperator = new char[] { ' ', '\t', '*', '.' }; string line; string firstWord; string secondWord; @@ -131,7 +134,7 @@ namespace DnsServerCore.Dns.ZoneManagers if (line == null) break; //eof - line = line.TrimStart(' ', '\t', '*', '.'); + line = line.TrimStart(trimSeperator); if (line.Length == 0) continue; //skip empty line