Use ReadOnlyMemory<byte> for binary data to eliminate UTF-16 transcoding (#1070)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: stephentoub <2642209+stephentoub@users.noreply.github.com> Co-authored-by: ericstj <8918108+ericstj@users.noreply.github.com> Co-authored-by: Eric StJohn <ericstj@microsoft.com>
This commit is contained in:
parent
a3ce9e9606
commit
80b1ad21d7
1 changed files with 400 additions and 103 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System.Buffers;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
|
|
@ -78,7 +79,7 @@ public abstract class ResourceContents
|
|||
|
||||
string? uri = null;
|
||||
string? mimeType = null;
|
||||
string? blob = null;
|
||||
ReadOnlyMemory<byte>? blob = null;
|
||||
string? text = null;
|
||||
JsonObject? meta = null;
|
||||
|
||||
|
|
@ -104,7 +105,7 @@ public abstract class ResourceContents
|
|||
break;
|
||||
|
||||
case "blob":
|
||||
blob = reader.GetString();
|
||||
blob = reader.HasValueSequence ? reader.ValueSequence.ToArray() : reader.ValueSpan.ToArray();
|
||||
break;
|
||||
|
||||
case "text":
|
||||
|
|
@ -127,7 +128,7 @@ public abstract class ResourceContents
|
|||
{
|
||||
Uri = uri ?? string.Empty,
|
||||
MimeType = mimeType,
|
||||
Blob = blob,
|
||||
Blob = blob.Value,
|
||||
Meta = meta,
|
||||
};
|
||||
}
|
||||
|
|
@ -162,7 +163,7 @@ public abstract class ResourceContents
|
|||
Debug.Assert(value is BlobResourceContents or TextResourceContents);
|
||||
if (value is BlobResourceContents blobResource)
|
||||
{
|
||||
writer.WriteString("blob", blobResource.Blob);
|
||||
writer.WriteString("blob", blobResource.Blob.Span);
|
||||
}
|
||||
else if (value is TextResourceContents textResource)
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue