fix: Eliminates string allocations while writing gump packets (#1017)
* Introduces `RawInterpolatedStringHandler` which is exactly the same as `DefaultInterpolatedStringHandler` except it _unsafely exposes_ it's `ReadOnlySpan<char>` buffer. This is useful for writing the string's data without actually building the string. * Uses this new string interpolation handler in `SpanWriter` to eliminate intermediate strings built. This is immensely useful in eliminating string allocations in writing Gump packets.
This commit is contained in:
parent
f7cbeacf48
commit
87b63b38a5
7 changed files with 674 additions and 43 deletions
|
|
@ -105,7 +105,7 @@ namespace Server.Text
|
|||
public static int GetBytesUtf8(this ReadOnlySpan<char> str, Span<byte> buffer) => UTF8.GetBytes(str, buffer);
|
||||
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
public static int GetByteLengthForEncoding(Encoding encoding) =>
|
||||
public static int GetByteLengthForEncoding(this Encoding encoding) =>
|
||||
encoding.BodyName switch
|
||||
{
|
||||
"utf-16BE" => 2,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue