From b45461095e973d749bdd59115ba6600703170920 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 2 Feb 2017 17:24:07 +0000 Subject: [PATCH] Support Encoding devirtualization --- src/mscorlib/src/System/Text/ASCIIEncoding.cs | 6 +++++- src/mscorlib/src/System/Text/UTF8Encoding.cs | 9 ++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/mscorlib/src/System/Text/ASCIIEncoding.cs b/src/mscorlib/src/System/Text/ASCIIEncoding.cs index 307e489..34b04a0 100644 --- a/src/mscorlib/src/System/Text/ASCIIEncoding.cs +++ b/src/mscorlib/src/System/Text/ASCIIEncoding.cs @@ -23,9 +23,13 @@ namespace System.Text [Serializable] public class ASCIIEncoding : Encoding { + // Allow for devirtualization (see https://github.com/dotnet/coreclr/pull/9230) + [Serializable] + internal sealed class ASCIIEncodingSealed : ASCIIEncoding { } + // Used by Encoding.ASCII for lazy initialization // The initialization code will not be run until a static member of the class is referenced - internal static readonly ASCIIEncoding s_default = new ASCIIEncoding(); + internal static readonly ASCIIEncodingSealed s_default = new ASCIIEncodingSealed(); public ASCIIEncoding() : base(Encoding.CodePageASCII) { diff --git a/src/mscorlib/src/System/Text/UTF8Encoding.cs b/src/mscorlib/src/System/Text/UTF8Encoding.cs index b2cc462..65d9bf9 100644 --- a/src/mscorlib/src/System/Text/UTF8Encoding.cs +++ b/src/mscorlib/src/System/Text/UTF8Encoding.cs @@ -53,9 +53,16 @@ namespace System.Text private const int UTF8_CODEPAGE = 65001; + // Allow for devirtualization (see https://github.com/dotnet/coreclr/pull/9230) + [Serializable] + internal sealed class UTF8EncodingSealed : UTF8Encoding + { + public UTF8EncodingSealed() : base(encoderShouldEmitUTF8Identifier: true) { } + } + // Used by Encoding.UTF8 for lazy initialization // The initialization code will not be run until a static member of the class is referenced - internal static readonly UTF8Encoding s_default = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true); + internal static readonly UTF8EncodingSealed s_default = new UTF8EncodingSealed(); // Yes, the idea of emitting U+FEFF as a UTF-8 identifier has made it into // the standard. -- 2.7.4