Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Support Encoding devirtualization
Browse files Browse the repository at this point in the history
  • Loading branch information
benaadams committed Feb 2, 2017
1 parent cfca388 commit 84972f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/mscorlib/src/System/Text/ASCIIEncoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ namespace System.Text
[System.Runtime.InteropServices.ComVisible(true)]
public class ASCIIEncoding : Encoding
{
// Allow for devirtualization (see https://github.com/dotnet/coreclr/pull/9230)
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)
{
Expand Down
9 changes: 7 additions & 2 deletions src/mscorlib/src/System/Text/UTF8Encoding.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,15 @@ public class UTF8Encoding : Encoding
*/

private const int UTF8_CODEPAGE=65001;


// Allow for devirtualization (see https://github.com/dotnet/coreclr/pull/9230)
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.
Expand Down

0 comments on commit 84972f9

Please sign in to comment.