fix: increase termination efficiency
This commit is contained in:
parent
36222d017f
commit
9a03ad1a07
|
@ -4,9 +4,9 @@ namespace ChatTwo.Util;
|
||||||
|
|
||||||
internal static class StringUtil {
|
internal static class StringUtil {
|
||||||
internal static byte[] ToTerminatedBytes(this string s) {
|
internal static byte[] ToTerminatedBytes(this string s) {
|
||||||
var unterminated = Encoding.UTF8.GetBytes(s);
|
var utf8 = Encoding.UTF8;
|
||||||
var bytes = new byte[unterminated.Length + 1];
|
var bytes = new byte[utf8.GetByteCount(s) + 1];
|
||||||
Array.Copy(unterminated, bytes, unterminated.Length);
|
utf8.GetBytes(s, 0, s.Length, bytes, 0);
|
||||||
bytes[^1] = 0;
|
bytes[^1] = 0;
|
||||||
return bytes;
|
return bytes;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user