Use custom GetPinnableReference instead of deferring it to Span (#2345)

This commit is contained in:
srkizer 2025-08-07 01:03:50 +09:00 committed by GitHub
parent 2cd5c5bc68
commit 3e40cad063
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 107 additions and 52 deletions

View file

@ -169,6 +169,28 @@ public ref struct ImU8String : IDisposable
public static unsafe implicit operator ImU8String(byte* text) => new(text);
public static unsafe implicit operator ImU8String(char* text) => new(text);
public ref readonly byte GetPinnableReference()
{
if (this.IsNull)
return ref Unsafe.NullRef<byte>();
if (this.IsEmpty)
return ref this.FixedBufferSpan[0];
return ref this.Span.GetPinnableReference();
}
public ref readonly byte GetPinnableReference(ReadOnlySpan<byte> defaultValue)
{
if (this.IsNull)
return ref defaultValue.GetPinnableReference();
if (this.IsEmpty)
return ref this.FixedBufferSpan[0];
return ref this.Span.GetPinnableReference();
}
public ref readonly byte GetPinnableNullTerminatedReference(ReadOnlySpan<byte> defaultValue = default)
{
if (this.IsNull)