Skip to content

Commit 353579a

Browse files
author
yupliner
committed
Remove allocation of Encoding
1 parent a02a0b1 commit 353579a

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

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)