From a5f93fd19466924cdc051f1f04ffb22401eb5c20 Mon Sep 17 00:00:00 2001 From: Anna Date: Fri, 3 Jun 2022 19:56:24 -0400 Subject: [PATCH] fix: increase termination efficiency --- ChatTwo/Util/StringUtil.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ChatTwo/Util/StringUtil.cs b/ChatTwo/Util/StringUtil.cs index 82b4aa5..b92fb62 100755 --- a/ChatTwo/Util/StringUtil.cs +++ b/ChatTwo/Util/StringUtil.cs @@ -4,9 +4,9 @@ namespace ChatTwo.Util; internal static class StringUtil { internal static byte[] ToTerminatedBytes(this string s) { - var unterminated = Encoding.UTF8.GetBytes(s); - var bytes = new byte[unterminated.Length + 1]; - Array.Copy(unterminated, bytes, unterminated.Length); + var utf8 = Encoding.UTF8; + var bytes = new byte[utf8.GetByteCount(s) + 1]; + utf8.GetBytes(s, 0, s.Length, bytes, 0); bytes[^1] = 0; return bytes; }