From: Jean-Philippe Bruyère Date: Wed, 13 May 2020 20:23:56 +0000 (+0200) Subject: try FastEnum X-Git-Tag: v0.9.5-beta~113^2~29 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=31125f2b7fc7517a324e90058bce2f2cec063f7c;p=jp%2Fcrow.git try FastEnum --- diff --git a/Crow/Crow.csproj b/Crow/Crow.csproj index bc5594aa..94977dec 100644 --- a/Crow/Crow.csproj +++ b/Crow/Crow.csproj @@ -1,7 +1,7 @@ - netstandard2.0 + netstandard2.0 $(CrowVersion) $(CrowVersion) @@ -40,6 +40,7 @@ + $(DefineConstants);STB_SHARP diff --git a/Crow/src/Colors.cs b/Crow/src/Colors.cs index 763aed07..d33db179 100644 --- a/Crow/src/Colors.cs +++ b/Crow/src/Colors.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using FastEnumUtility; namespace Crow { @@ -327,7 +328,7 @@ namespace Crow => value.GetHashCode (); public override string ToString() - => Enum.IsDefined (typeof (Colors), value) ? ((Colors)value).ToString () : HtmlCode; + => FastEnum.IsDefined (value) ? FastEnum.GetName((Colors)value) : HtmlCode; public static Color FromIml (string iml) { @@ -343,7 +344,7 @@ namespace Crow => (string.IsNullOrEmpty (s)) ? new Color (Colors.White) : (s.StartsWith ("#", StringComparison.Ordinal)) ? new Color (UInt32.Parse (s.Substring (1), System.Globalization.NumberStyles.HexNumber)) : (char.IsDigit(s[0])) ? FromIml (s) : - (Enum.TryParse (s, out Colors cc)) ? new Color(cc) : + (FastEnum.TryParse (s, out Colors cc)) ? new Color(cc) : throw new Exception ("Unknown color name: " + s); diff --git a/Crow/src/Font.cs b/Crow/src/Font.cs index 06df4a88..4bf5fab3 100644 --- a/Crow/src/Font.cs +++ b/Crow/src/Font.cs @@ -26,6 +26,7 @@ using System; using Crow.Cairo; +using FastEnumUtility; namespace Crow { @@ -102,7 +103,7 @@ namespace Crow f.Name = n [0]; if (n.Length > 1) - f.Style = (FontStyle)Enum.Parse (typeof(FontStyle), n[n.Length-1], true); + f.Style = FastEnum.Parse (n[n.Length-1], true); } return f; diff --git a/Crow/src/IML/CompilerServices.cs b/Crow/src/IML/CompilerServices.cs index 847292eb..ffd5f34c 100644 --- a/Crow/src/IML/CompilerServices.cs +++ b/Crow/src/IML/CompilerServices.cs @@ -12,6 +12,7 @@ using System.Runtime.CompilerServices; using System.Xml; using Crow.IML; using System.Text; +using FastEnumUtility; namespace Crow.IML { diff --git a/Crow/src/Widgets/DockStack.cs b/Crow/src/Widgets/DockStack.cs index 0e8c9802..50e87b1c 100644 --- a/Crow/src/Widgets/DockStack.cs +++ b/Crow/src/Widgets/DockStack.cs @@ -28,6 +28,7 @@ using Crow.IML; using System.Linq; using System.Text; using System.IO; +using FastEnumUtility; namespace Crow { @@ -389,7 +390,7 @@ namespace Crow ClearChildren (); stretchedChild = null; int i = 0; - Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + Orientation = FastEnum.Parse (getConfAttrib (conf, ref i)); importConfig (conf, ref i, dataSource); } } @@ -415,7 +416,7 @@ namespace Crow dw.Name = wName; dw.Width = Measure.Parse (getConfAttrib (conf, ref i)); dw.Height = Measure.Parse (getConfAttrib (conf, ref i)); - dw.DockingPosition = (Alignment)Enum.Parse (typeof(Alignment), getConfAttrib (conf, ref i)); + dw.DockingPosition = FastEnum.Parse (getConfAttrib (conf, ref i)); dw.savedSlot = Rectangle.Parse (getConfAttrib (conf, ref i)); dw.wasResizable = Boolean.Parse (getConfAttrib (conf, ref i)); @@ -428,7 +429,7 @@ namespace Crow DockStack ds = new DockStack (IFace); ds.Width = Measure.Parse (getConfAttrib (conf, ref i)); ds.Height = Measure.Parse (getConfAttrib (conf, ref i)); - ds.Orientation = (Orientation)Enum.Parse (typeof(Orientation), getConfAttrib (conf, ref i)); + ds.Orientation = FastEnum.Parse (getConfAttrib (conf, ref i)); this.AddChild (ds); diff --git a/PerfTests/Program.cs b/PerfTests/Program.cs index e97014df..8b83a592 100644 --- a/PerfTests/Program.cs +++ b/PerfTests/Program.cs @@ -50,7 +50,7 @@ namespace PerfTests void testDir (string dirPath, int level = 0) { - Console.WriteLine ($"{new string (' ', level * 4)}-{dirPath}"); + Console.WriteLine ($"{new string (' ', level * 4)}- {dirPath}"); level++; foreach (string d in Directory.GetDirectories (dirPath)) @@ -59,10 +59,10 @@ namespace PerfTests foreach (string f in Directory.GetFiles (dirPath)) { try { long mean = Test (f, out long min, out long max); - Console.WriteLine ($"{new string (' ', level * 4)}{ Path.GetFileName (f),-30}: {min,5} |{mean,5} |{max,5}"); + Console.WriteLine ($"{new string (' ', level * 4)}{ Path.GetFileName (f),-30}|{min,5}|{mean,5}|{max,5}"); } catch (Exception ex) { Console.ForegroundColor = ConsoleColor.Red; - Console.WriteLine ($"{ex.Message}"); + Console.WriteLine ($"- {ex.Message}"); Console.ResetColor (); } }