fix: Fixes mobile titles not displaying properly (#1149)

This commit is contained in:
mark1145 2022-08-28 06:31:22 +10:00 committed by GitHub
parent 42f2c7f6ae
commit b8146f26f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 55 additions and 36 deletions

View file

@ -18,6 +18,12 @@ using System;
namespace Server.Buffers;
/// <summary>
/// Wrapper for STArray backed strings and char buffers that will be used in InterpolatedStringHandlers.
/// The wrapper prevents intermediate strings from being created unnecessarily.
/// Note: TryFormat can only be called once. Using the PooledArraySpanFormattable after calling TryFormat will throw.
/// To use the span multiple times, use the Chars property directly instead.
/// </summary>
public struct PooledArraySpanFormattable : ISpanFormattable, IDisposable
{
private char[] _arrayToReturnToPool;
@ -42,6 +48,7 @@ public struct PooledArraySpanFormattable : ISpanFormattable, IDisposable
STArrayPool<char>.Shared.Return(_arrayToReturnToPool);
_arrayToReturnToPool = null;
// We don't dispose so we can call ToString() multiple times with idempotence.
return _value;
}
@ -58,6 +65,9 @@ public struct PooledArraySpanFormattable : ISpanFormattable, IDisposable
_arrayToReturnToPool.AsSpan(0, _pos).CopyTo(destination);
charsWritten = _pos;
// Interpolated string handlers do not dispose, but we need to return the chars to the array.
Dispose();
return true;
}