From 1b71a36e5fdfe8616271828b1c48cf5fe604d07f Mon Sep 17 00:00:00 2001 From: Justin Van Patten Date: Thu, 10 Nov 2016 06:58:33 -0800 Subject: [PATCH] BinaryReader: Use cached default encoding instance (#8017) A new instance of UTF8Encoding used to be created every time BinaryReader.ctor(Stream) was called, which created an instance of UTF8Encoding that has no preamble. However, BinaryReader does not use the preamble at all, so it doesn't matter if the encoding has a preamble or not. Thus, the cached Encoding.UTF8 instance can be used (which has a preamble). --- src/mscorlib/src/System/IO/BinaryReader.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mscorlib/src/System/IO/BinaryReader.cs b/src/mscorlib/src/System/IO/BinaryReader.cs index ef8245f..c7eff0f 100644 --- a/src/mscorlib/src/System/IO/BinaryReader.cs +++ b/src/mscorlib/src/System/IO/BinaryReader.cs @@ -40,7 +40,7 @@ namespace System.IO { private bool m_isMemoryStream; // "do we sit on MemoryStream?" for Read/ReadInt32 perf private bool m_leaveOpen; - public BinaryReader(Stream input) : this(input, new UTF8Encoding(), false) { + public BinaryReader(Stream input) : this(input, Encoding.UTF8, false) { } public BinaryReader(Stream input, Encoding encoding) : this(input, encoding, false) { -- 2.7.4