Skip to content

Commit be28817

Browse files
authored
Merge pull request #477 from Pliner/redundant-allocations
Remove redundant allocations
2 parents c15df5f + 353579a commit be28817

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

projects/client/RabbitMQ.Client/src/client/impl/SocketFrameHandler.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,10 @@ public void WriteFrameSet(IList<OutboundFrame> frames)
238238
{
239239
var ms = new MemoryStream();
240240
var nbw = new NetworkBinaryWriter(ms);
241-
foreach (var f in frames) f.WriteTo(nbw);
241+
for (var i = 0; i < frames.Count; ++i)
242+
{
243+
frames[i].WriteTo(nbw);
244+
}
242245
m_socket.Client.Poll(m_writeableStateTimeout, SelectMode.SelectWrite);
243246
Write(ms.GetBufferSegment());
244247
}

projects/client/RabbitMQ.Client/src/util/NetworkBinaryReader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41-
using System;
4241
using System.IO;
4342
using System.Text;
4443

@@ -55,6 +54,8 @@ namespace RabbitMQ.Util
5554
/// </remarks>
5655
public class NetworkBinaryReader : BinaryReader
5756
{
57+
private static readonly Encoding encoding = new UTF8Encoding();
58+
5859
// Not particularly efficient. To be more efficient, we could
5960
// reuse BinaryReader's implementation details: m_buffer and
6061
// FillBuffer, if they weren't private
@@ -65,7 +66,7 @@ public class NetworkBinaryReader : BinaryReader
6566
/// <summary>
6667
/// Construct a NetworkBinaryReader over the given input stream.
6768
/// </summary>
68-
public NetworkBinaryReader(Stream input) : base(input)
69+
public NetworkBinaryReader(Stream input) : base(input, encoding)
6970
{
7071
}
7172

projects/client/RabbitMQ.Client/src/util/NetworkBinaryWriter.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
3939
//---------------------------------------------------------------------------
4040

41-
using System;
4241
using System.IO;
4342
using System.Text;
4443

@@ -57,10 +56,12 @@ namespace RabbitMQ.Util
5756
/// </remarks>
5857
public class NetworkBinaryWriter : BinaryWriter
5958
{
59+
private static readonly Encoding encoding = new UTF8Encoding(false, true);
60+
6061
/// <summary>
6162
/// Construct a NetworkBinaryWriter over the given input stream.
6263
/// </summary>
63-
public NetworkBinaryWriter(Stream output) : base(output)
64+
public NetworkBinaryWriter(Stream output) : base(output, encoding)
6465
{
6566
}
6667

0 commit comments

Comments
 (0)