From: Jean-Philippe Bruyère Date: Thu, 4 Mar 2021 15:50:19 +0000 (+0100) Subject: use stringbuilder for shape expression parsing X-Git-Tag: v0.9.5-beta~64 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=c74dc5437430279afe0ab9255c9022acabef2b8b;p=jp%2Fcrow.git use stringbuilder for shape expression parsing --- diff --git a/Crow/src/Widgets/Shape.cs b/Crow/src/Widgets/Shape.cs index 020b0a71..dd8fefdf 100644 --- a/Crow/src/Widgets/Shape.cs +++ b/Crow/src/Widgets/Shape.cs @@ -36,29 +36,31 @@ namespace Crow public class PathParser : StringReader { public PathParser (string str) : base (str) { } - + char[] buffer = new char[20]; double readDouble () { - StringBuilder tmp = new StringBuilder (); + int length = 0; while (Peek () >= 0) { - char c = (char)Read (); - if (c.IsWhiteSpaceOrNewLine ()) { - if (tmp.Length == 0) + buffer[length] = (char)Read (); + if (buffer[length].IsWhiteSpaceOrNewLine ()) { + if (length == 0) continue; else break; - } else if (c == ',') + } else if (buffer[length] == ',') break; - tmp.Append (c); + length++; } - return double.Parse (tmp.ToString ()); + return double.Parse (buffer.AsSpan(0, length)); } public void Draw (Context gr, bool measure = false) { + char c; + try { while (Peek () >= 0) { - char c = (char)Read (); + c = (char)Read (); if (c.IsWhiteSpaceOrNewLine ()) continue; switch (c) {