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:
Kamron Batman 2022-05-10 18:50:23 -07:00 committed by GitHub
parent f7cbeacf48
commit 87b63b38a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 674 additions and 43 deletions

View file

@ -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,