Skip to content

Remove redundant allocations #477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,10 @@ public void WriteFrameSet(IList<OutboundFrame> frames)
{
var ms = new MemoryStream();
var nbw = new NetworkBinaryWriter(ms);
foreach (var f in frames) f.WriteTo(nbw);
for (var i = 0; i < frames.Count; ++i)
{
frames[i].WriteTo(nbw);
}
m_socket.Client.Poll(m_writeableStateTimeout, SelectMode.SelectWrite);
Write(ms.GetBufferSegment());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;
using System.IO;
using System.Text;

Expand All @@ -55,6 +54,8 @@ namespace RabbitMQ.Util
/// </remarks>
public class NetworkBinaryReader : BinaryReader
{
private static readonly Encoding encoding = new UTF8Encoding();

// Not particularly efficient. To be more efficient, we could
// reuse BinaryReader's implementation details: m_buffer and
// FillBuffer, if they weren't private
Expand All @@ -65,7 +66,7 @@ public class NetworkBinaryReader : BinaryReader
/// <summary>
/// Construct a NetworkBinaryReader over the given input stream.
/// </summary>
public NetworkBinaryReader(Stream input) : base(input)
public NetworkBinaryReader(Stream input) : base(input, encoding)
{
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
// Copyright (c) 2007-2016 Pivotal Software, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;
using System.IO;
using System.Text;

Expand All @@ -57,10 +56,12 @@ namespace RabbitMQ.Util
/// </remarks>
public class NetworkBinaryWriter : BinaryWriter
{
private static readonly Encoding encoding = new UTF8Encoding(false, true);

/// <summary>
/// Construct a NetworkBinaryWriter over the given input stream.
/// </summary>
public NetworkBinaryWriter(Stream output) : base(output)
public NetworkBinaryWriter(Stream output) : base(output, encoding)
{
}

Expand Down