From 111551cfe32e9353723ee0968c89ece794b6d037 Mon Sep 17 00:00:00 2001 From: ktlwap <149824361+ktlwap@users.noreply.github.com> Date: Fri, 19 Apr 2024 19:36:53 +0200 Subject: [PATCH] Remove unnecessary string allocations --- src/FontStash.NET/Fontstash.Api.cs | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/FontStash.NET/Fontstash.Api.cs b/src/FontStash.NET/Fontstash.Api.cs index a01af94..6914c64 100644 --- a/src/FontStash.NET/Fontstash.Api.cs +++ b/src/FontStash.NET/Fontstash.Api.cs @@ -395,11 +395,10 @@ public float DrawText(float x, float y, string str, string end) for (int i = 0; i < str.Length; i++) { - char c = str[i]; - if (str[i..] == end) + if (end != null && string.Compare(str, i, end, 0, end.Length) == 0) break; - - if (Utf8.DecUtf8(ref utf8state, ref codepoint, c) != 0) + + if (Utf8.DecUtf8(ref utf8state, ref codepoint, str[i]) != 0) continue; glyph = GetGlyph(font, codepoint, isize, iblur, FonsGlyphBitmap.Requiered); if (glyph != null) @@ -458,7 +457,7 @@ public float TextBounds(float x, float y, string str, string end, out float[] bo for (int i = 0; i < str.Length; i++) { char c = str[i]; - if (str[i..] == end) + if (end != null && string.Compare(str, i, end, 0, end.Length) == 0) break; if (Utf8.DecUtf8(ref utf8state, ref codepoint, c) != 0) @@ -619,11 +618,10 @@ public bool TextIterNext(ref FonsTextIter iter, ref FonsQuad quad) int i; for (i = 0; i < str.Length; i++) { - char c = str[i]; - if (str[i..] == iter.end) + if (iter.end != null && string.Compare(str, i, iter.end, 0, iter.end.Length) == 0) break; - if (Utf8.DecUtf8(ref iter.utf8state, ref iter.codepoint, c) != 0) + if (Utf8.DecUtf8(ref iter.utf8state, ref iter.codepoint, str[i]) != 0) continue; iter.x = iter.nextx;