Don't copy the array for incoming msgpack reads (#1686)
* Don't copy the array for incoming msgpack reads - Don't use ToArray on the already sliced msgpack data. - Turns out msgpack is self describing enough to not require the count, it just needs the buffer and start offset.
This commit is contained in:
parent
3f84eee116
commit
b111c91cb0
|
|
@ -3,8 +3,10 @@
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Runtime.ExceptionServices;
|
using System.Runtime.ExceptionServices;
|
||||||
|
using System.Runtime.InteropServices;
|
||||||
using Microsoft.AspNetCore.Protocols;
|
using Microsoft.AspNetCore.Protocols;
|
||||||
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
using Microsoft.AspNetCore.SignalR.Internal.Formatters;
|
||||||
using Microsoft.AspNetCore.Sockets;
|
using Microsoft.AspNetCore.Sockets;
|
||||||
|
|
@ -41,15 +43,18 @@ namespace Microsoft.AspNetCore.SignalR.Internal.Protocol
|
||||||
{
|
{
|
||||||
while (BinaryMessageParser.TryParseMessage(ref input, out var payload))
|
while (BinaryMessageParser.TryParseMessage(ref input, out var payload))
|
||||||
{
|
{
|
||||||
messages.Add(ParseMessage(payload.ToArray(), binder));
|
var isArray = MemoryMarshal.TryGetArray(payload, out var arraySegment);
|
||||||
|
// This will never be false unless we started using un-managed buffers
|
||||||
|
Debug.Assert(isArray);
|
||||||
|
messages.Add(ParseMessage(arraySegment.Array, arraySegment.Offset, binder));
|
||||||
}
|
}
|
||||||
|
|
||||||
return messages.Count > 0;
|
return messages.Count > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static HubMessage ParseMessage(byte[] input, IInvocationBinder binder)
|
private static HubMessage ParseMessage(byte[] input, int startOffset, IInvocationBinder binder)
|
||||||
{
|
{
|
||||||
using (var unpacker = Unpacker.Create(input))
|
using (var unpacker = Unpacker.Create(input, startOffset))
|
||||||
{
|
{
|
||||||
_ = ReadArrayLength(unpacker, "elementCount");
|
_ = ReadArrayLength(unpacker, "elementCount");
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue