fix: increase termination efficiency
This commit is contained in:
parent
65fb1f5cce
commit
a5f93fd194
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue