Skip to content

Commit cdba736

Browse files
committed
Utilize ArrayBuilder
1 parent 8aeef7d commit cdba736

File tree

4 files changed

+9
-3
lines changed

4 files changed

+9
-3
lines changed

src/Components/Shared/src/ArrayBuilder.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ namespace Ignitor
1414
namespace Microsoft.AspNetCore.Components.WebView
1515
#elif COMPONENTS_SERVER
1616
namespace Microsoft.AspNetCore.Components.Server.Circuits
17+
#elif JS_INTEROP
18+
namespace Microsoft.JSInterop.Infrastructure
1719
#else
1820
namespace Microsoft.AspNetCore.Components.RenderTree
1921
#endif

src/JSInterop/Microsoft.JSInterop/src/Infrastructure/ByteArrayJsonConverter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal sealed class ByteArrayJsonConverter : JsonConverter<byte[]>
2121
/// <summary>
2222
/// Contains the byte array(s) being serialized.
2323
/// </summary>
24-
internal readonly List<byte[]> ByteArraysToSerialize = new();
24+
internal readonly ArrayBuilder<byte[]> ByteArraysToSerialize = new();
2525

2626
/// <summary>
2727
/// Sets the byte array(s) being deserialized.
@@ -106,7 +106,7 @@ public override void Write(Utf8JsonWriter writer, byte[] value, JsonSerializerOp
106106

107107
var id = ByteArraysToSerialize.Count;
108108

109-
ByteArraysToSerialize.Add(value);
109+
ByteArraysToSerialize.Append(value);
110110

111111
writer.WriteStartObject();
112112
writer.WriteNumber(ByteArrayRefKey, id);

src/JSInterop/Microsoft.JSInterop/src/Infrastructure/DotNetDispatcher.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,9 @@ internal static SerializedArgs SerializeArgs(JSRuntime jsRuntime, object? args)
319319
}
320320

321321
var serializedArgs = JsonSerializer.Serialize(args, jsRuntime.JsonSerializerOptions);
322-
var byteArrays = jsRuntime.ByteArrayJsonConverter.ByteArraysToSerialize.ToArray();
322+
var numByteArrays = jsRuntime.ByteArrayJsonConverter.ByteArraysToSerialize.Count;
323+
var byteArrays = new byte[numByteArrays][];
324+
Array.Copy(jsRuntime.ByteArrayJsonConverter.ByteArraysToSerialize.Buffer, byteArrays, numByteArrays);
323325
jsRuntime.ByteArrayJsonConverter.ByteArraysToSerialize.Clear();
324326
jsRuntime.ByteArrayJsonConverter.WriteSemaphore.Release();
325327

src/JSInterop/Microsoft.JSInterop/src/Microsoft.JSInterop.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,13 @@
88
<IsAspNetCoreApp>true</IsAspNetCoreApp>
99
<Nullable>enable</Nullable>
1010
<Trimmable>true</Trimmable>
11+
<DefineConstants>$(DefineConstants);JS_INTEROP</DefineConstants>
1112
</PropertyGroup>
1213

1314
<ItemGroup>
1415
<Compile Include="$(SharedSourceRoot)JSInterop\JSCallResultTypeHelper.cs" LinkBase="Shared" />
1516
<Compile Include="$(SharedSourceRoot)LinkerFlags.cs" LinkBase="Shared" />
17+
<Compile Include="$(RepoRoot)\src\Components\Shared\src\ArrayBuilder.cs" />
1618
</ItemGroup>
1719

1820
<ItemGroup>

0 commit comments

Comments
 (0)