Improve NullHtmlEncoder perf (#7987)

Fixes #7987
This commit is contained in:
Pranav K 2019-03-05 14:41:55 -08:00 committed by GitHub
commit b90220ad05
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 15 deletions

View File

@ -61,17 +61,17 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
void Init(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context);
System.Threading.Tasks.Task ProcessAsync(Microsoft.AspNetCore.Razor.TagHelpers.TagHelperContext context, Microsoft.AspNetCore.Razor.TagHelpers.TagHelperOutput output);
}
public partial class NullHtmlEncoder : System.Text.Encodings.Web.HtmlEncoder
public sealed partial class NullHtmlEncoder : System.Text.Encodings.Web.HtmlEncoder
{
protected NullHtmlEncoder() { }
internal NullHtmlEncoder() { }
public static new Microsoft.AspNetCore.Razor.TagHelpers.NullHtmlEncoder Default { [System.Runtime.CompilerServices.CompilerGeneratedAttribute]get { throw null; } }
public override int MaxOutputCharactersPerInputCharacter { get { throw null; } }
public override void Encode(System.IO.TextWriter output, char[] value, int startIndex, int characterCount) { }
public override void Encode(System.IO.TextWriter output, string value, int startIndex, int characterCount) { }
public override string Encode(string value) { throw null; }
public unsafe override int FindFirstCharacterToEncode(char* text, int textLength) { throw null; }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public unsafe override int FindFirstCharacterToEncode(char* text, int textLength) { throw null; }
public unsafe override bool TryEncodeUnicodeScalar(int unicodeScalar, char* buffer, int bufferLength, out int numberOfCharactersWritten) { throw null; }
public override bool WillEncode(int unicodeScalar) { throw null; }
[System.Runtime.CompilerServices.MethodImpl(System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)]public override bool WillEncode(int unicodeScalar) { throw null; }
}
[System.AttributeUsageAttribute(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed partial class OutputElementHintAttribute : System.Attribute

View File

@ -3,6 +3,7 @@
using System;
using System.IO;
using System.Runtime.CompilerServices;
using System.Text.Encodings.Web;
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
/// expected to contain valid HTML.
/// </summary>
public class NullHtmlEncoder : HtmlEncoder
public sealed class NullHtmlEncoder : HtmlEncoder
{
/// <summary>
/// Initializes a <see cref="NullHtmlEncoder"/> instance.
/// </summary>
protected NullHtmlEncoder()
private NullHtmlEncoder()
{
}
@ -27,13 +28,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
public static new NullHtmlEncoder Default { get; } = new NullHtmlEncoder();
/// <inheritdoc />
public override int MaxOutputCharactersPerInputCharacter
{
get
{
return 1;
}
}
public override int MaxOutputCharactersPerInputCharacter => 1;
/// <inheritdoc />
public override string Encode(string value)
@ -67,7 +62,6 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
output.Write(value, startIndex, characterCount);
}
/// <inheritdoc />
public override void Encode(TextWriter output, string value, int startIndex, int characterCount)
{
if (output == null)
@ -85,10 +79,13 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
return;
}
output.Write(value.Substring(startIndex, characterCount));
var span = value.AsSpan(startIndex, characterCount);
output.Write(span);
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override unsafe int FindFirstCharacterToEncode(char* text, int textLength)
{
return -1;
@ -112,6 +109,7 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers
}
/// <inheritdoc />
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override bool WillEncode(int unicodeScalar)
{
return false;