Improve NullHtmlEncoder perf

This commit is contained in:
Sebastien Ros 2019-02-26 16:25:10 -08:00
parent a7f1cc1b2a
commit 55fea7976c
1 changed files with 6 additions and 30 deletions

View File

@ -3,6 +3,7 @@
using System; using System;
using System.IO; using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Encodings.Web; using System.Text.Encodings.Web;
namespace Microsoft.AspNetCore.Razor.TagHelpers namespace Microsoft.AspNetCore.Razor.TagHelpers
@ -11,12 +12,12 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
/// A <see cref="HtmlEncoder"/> that does not encode. Should not be used when writing directly to a response /// A <see cref="HtmlEncoder"/> that does not encode. Should not be used when writing directly to a response
/// expected to contain valid HTML. /// expected to contain valid HTML.
/// </summary> /// </summary>
public class NullHtmlEncoder : HtmlEncoder public sealed class NullHtmlEncoder : HtmlEncoder
{ {
/// <summary> /// <summary>
/// Initializes a <see cref="NullHtmlEncoder"/> instance. /// Initializes a <see cref="NullHtmlEncoder"/> instance.
/// </summary> /// </summary>
protected NullHtmlEncoder() private NullHtmlEncoder()
{ {
} }
@ -27,13 +28,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
public static new NullHtmlEncoder Default { get; } = new NullHtmlEncoder(); public static new NullHtmlEncoder Default { get; } = new NullHtmlEncoder();
/// <inheritdoc /> /// <inheritdoc />
public override int MaxOutputCharactersPerInputCharacter public override int MaxOutputCharactersPerInputCharacter => 1;
{
get
{
return 1;
}
}
/// <inheritdoc /> /// <inheritdoc />
public override string Encode(string value) public override string Encode(string value)
@ -68,27 +63,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
public override void Encode(TextWriter output, string value, int startIndex, int characterCount) [MethodImpl(MethodImplOptions.AggressiveInlining)]
{
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
if (value == null)
{
throw new ArgumentNullException(nameof(value));
}
if (characterCount == 0)
{
return;
}
output.Write(value.Substring(startIndex, characterCount));
}
/// <inheritdoc />
public override unsafe int FindFirstCharacterToEncode(char* text, int textLength) public override unsafe int FindFirstCharacterToEncode(char* text, int textLength)
{ {
return -1; return -1;
@ -112,6 +87,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
} }
/// <inheritdoc /> /// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool WillEncode(int unicodeScalar) public override bool WillEncode(int unicodeScalar)
{ {
return false; return false;