Skip to content

Commit 6c1ec26

Browse files
authored
Merge pull request #13 from StackExchange/memory-stream-allocs
Try to avoid an extra array alloc/copy in SendProtobuf
2 parents a1c2a14 + a543835 commit 6c1ec26

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

global.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"sdk": {
3-
"version": "2.2.100"
3+
"version": "2.2.100",
4+
"rollForward": "latestMajor",
5+
"allowPrerelease": false
46
}
57
}

src/StackExchange.Utils.Http/Extensions.Send.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ public static IRequestBuilder SendProtobuf(this IRequestBuilder builder, object
8888
{
8989
Serializer.Serialize(gzs, obj);
9090
gzs.Close();
91-
var protoContent = new ByteArrayContent(output.ToArray());
91+
var protoContent = output.TryGetBuffer(out var segment)
92+
? new ByteArrayContent(segment.Array, segment.Offset, segment.Count)
93+
: new ByteArrayContent(output.ToArray());
9294
protoContent.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
9395
protoContent.Headers.Add("Content-Encoding", "gzip");
9496
return SendContent(builder, protoContent);

0 commit comments

Comments
 (0)