From 5a5c6d04676e5dd239737a2baadbd371ff61d142 Mon Sep 17 00:00:00 2001 From: ZZYZX Date: Sat, 4 Feb 2017 17:25:48 +0200 Subject: [PATCH] Internal: ZScriptTokenizer shouldn't reinitialize static stuff on every construction --- Source/Core/Properties/AssemblyInfo.cs | 4 +- Source/Core/ZDoom/ZScriptTokenizer.cs | 62 ++++++++++--------- .../BuilderModes/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/Source/Core/Properties/AssemblyInfo.cs b/Source/Core/Properties/AssemblyInfo.cs index 6b3c39f1..59e8b07f 100755 --- a/Source/Core/Properties/AssemblyInfo.cs +++ b/Source/Core/Properties/AssemblyInfo.cs @@ -30,6 +30,6 @@ using CodeImp.DoomBuilder; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2857")] +[assembly: AssemblyVersion("2.3.0.2858")] [assembly: NeutralResourcesLanguageAttribute("en")] -[assembly: AssemblyHash("7e502a1")] +[assembly: AssemblyHash("e6ca495")] diff --git a/Source/Core/ZDoom/ZScriptTokenizer.cs b/Source/Core/ZDoom/ZScriptTokenizer.cs index 6dcfc7e6..1839bc2d 100755 --- a/Source/Core/ZDoom/ZScriptTokenizer.cs +++ b/Source/Core/ZDoom/ZScriptTokenizer.cs @@ -118,9 +118,9 @@ namespace CodeImp.DoomBuilder.ZDoom internal class ZScriptTokenizer { private BinaryReader reader; - private Dictionary namedtokentypes; // these are tokens that have precise equivalent in the enum (like operators) - private Dictionary namedtokentypesreverse; // these are tokens that have precise equivalent in the enum (like operators) - private List namedtokentypesorder; // this is the list of said tokens ordered by length. + private static Dictionary namedtokentypes; // these are tokens that have precise equivalent in the enum (like operators) + private static Dictionary namedtokentypesreverse; // these are tokens that have precise equivalent in the enum (like operators) + private static List namedtokentypesorder; // this is the list of said tokens ordered by length. public BinaryReader Reader { get { return reader; } } public long LastPosition { get; private set; } @@ -128,31 +128,35 @@ namespace CodeImp.DoomBuilder.ZDoom public ZScriptTokenizer(BinaryReader br) { reader = br; - namedtokentypes = new Dictionary(); - namedtokentypesreverse = new Dictionary(); - namedtokentypesorder = new List(); - // initialize the token type list. - IEnumerable tokentypes = Enum.GetValues(typeof(ZScriptTokenType)).Cast(); - foreach (ZScriptTokenType tokentype in tokentypes) - { - // - FieldInfo fi = typeof(ZScriptTokenType).GetField(tokentype.ToString()); - ZScriptTokenString[] attrs = (ZScriptTokenString[])fi.GetCustomAttributes(typeof(ZScriptTokenString), false); - if (attrs.Length == 0) continue; - // - namedtokentypes.Add(attrs[0].Value, tokentype); - namedtokentypesreverse.Add(tokentype, attrs[0].Value); - namedtokentypesorder.Add(attrs[0].Value); - } - namedtokentypesorder.Sort(delegate (string a, string b) + if (namedtokentypes == null || namedtokentypesreverse == null || namedtokentypesorder == null) { - if (a.Length > b.Length) - return -1; - if (a.Length < b.Length) - return 1; - return 0; - }); + namedtokentypes = new Dictionary(); + namedtokentypesreverse = new Dictionary(); + namedtokentypesorder = new List(); + // initialize the token type list. + IEnumerable tokentypes = Enum.GetValues(typeof(ZScriptTokenType)).Cast(); + foreach (ZScriptTokenType tokentype in tokentypes) + { + // + FieldInfo fi = typeof(ZScriptTokenType).GetField(tokentype.ToString()); + ZScriptTokenString[] attrs = (ZScriptTokenString[])fi.GetCustomAttributes(typeof(ZScriptTokenString), false); + if (attrs.Length == 0) continue; + // + namedtokentypes.Add(attrs[0].Value, tokentype); + namedtokentypesreverse.Add(tokentype, attrs[0].Value); + namedtokentypesorder.Add(attrs[0].Value); + } + + namedtokentypesorder.Sort(delegate (string a, string b) + { + if (a.Length > b.Length) + return -1; + if (a.Length < b.Length) + return 1; + return 0; + }); + } } public void SkipWhitespace() // note that this skips both whitespace, newlines AND comments @@ -512,13 +516,13 @@ namespace CodeImp.DoomBuilder.ZDoom } } } - catch (Exception ex) + catch (Exception) { try { reader.BaseStream.Position = cpos; } - catch (Exception ex2) + catch (Exception) { /* ... */ } @@ -570,7 +574,7 @@ namespace CodeImp.DoomBuilder.ZDoom tok.IsValid = false; return tok; } - catch (Exception ex) + catch (Exception) { return null; } diff --git a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs index 525b572c..1f755017 100755 --- a/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs +++ b/Source/Plugins/BuilderModes/Properties/AssemblyInfo.cs @@ -29,5 +29,5 @@ using System.Resources; // Build Number // Revision // -[assembly: AssemblyVersion("2.3.0.2857")] +[assembly: AssemblyVersion("2.3.0.2858")] [assembly: NeutralResourcesLanguageAttribute("en")]