refactor(opl): drop redundant Add(string) overload; OplTextBlock depends on IPropertyList

string converts implicitly to ReadOnlySpan<char>, so Add(ReadOnlySpan<char>) subsumes
Add(string); $"..." literals still bind to the interpolated-string-handler overload
(zero-alloc). OplTextBlock now holds an IPropertyList instead of the concrete
ObjectPropertyList.
This commit is contained in:
Kamron Batman 2026-06-22 10:01:39 -07:00
parent 88de585612
commit 42ae2a1146
4 changed files with 7 additions and 9 deletions

View file

@ -37,13 +37,15 @@ public class ObjectPropertyListSpanAddTests
}
[Fact]
public void SpanAdd_ProducesSameBytesAsStringAdd()
public void SpanAdd_ProducesSameBytesAsStringArgument()
{
// Add(int, string) routes through the interpolation InternalAdd; Add(int, ReadOnlySpan<char>)
// through the span InternalAdd. Both must produce identical bytes and hash.
var fromString = new ObjectPropertyList(null);
fromString.Add("Hello World");
fromString.Add(1070722, "Hello World");
var fromSpan = new ObjectPropertyList(null);
fromSpan.Add("Hello World".AsSpan());
fromSpan.Add(1070722, "Hello World".AsSpan());
Assert.Equal(Decode(fromString), Decode(fromSpan));
Assert.Equal(fromString.Hash, fromSpan.Hash);

View file

@ -29,9 +29,6 @@ public interface IPropertyList : ISelfInterpolatedStringHandler
/** Convenience method for $"{argument}". */
public void Add(int number, string argument);
/** Convenience method for $"{text}". */
public void Add(string text);
/** Convenience method for span-based text without allocating a string. */
public void Add(ReadOnlySpan<char> argument);

View file

@ -148,7 +148,6 @@ public sealed class ObjectPropertyList : IPropertyList, IDisposable
}
public void Add(int number, string? arguments) => InternalAdd(number, $"{arguments}");
public void Add(string argument) => InternalAdd(GetStringNumber(), $"{argument}");
public void Add(int number, int value) => InternalAdd(number, $"{value}");
public void AddLocalized(int value) => InternalAdd(GetStringNumber(), $"{value:#}");
public void AddLocalized(int number, int value) => InternalAdd(number, $"{value:#}");

View file

@ -23,11 +23,11 @@ namespace Server;
// Use with `using var block = list.TextBlock();`. ref struct: single-threaded OPL build only.
public ref struct OplTextBlock
{
private readonly ObjectPropertyList _list;
private readonly IPropertyList _list;
internal ValueStringBuilder _builder;
private bool _any;
internal OplTextBlock(ObjectPropertyList list)
internal OplTextBlock(IPropertyList list)
{
_list = list;
_builder = ValueStringBuilder.Create();