From cacd16fa854996af7ea11e3fd61bff9969022845 Mon Sep 17 00:00:00 2001 From: Ben Adams Date: Thu, 12 May 2016 20:41:47 +0100 Subject: [PATCH] Remove pragma warning disable 1998 Function doesn't need async --- .../Internal/TaskCache.cs | 24 +++++++++++++++++++ .../TagHelpers/TagHelperExecutionContext.cs | 3 ++- .../TagHelpers/TagHelper.cs | 6 ++--- 3 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 src/Microsoft.AspNetCore.Razor.Runtime/Internal/TaskCache.cs diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Internal/TaskCache.cs b/src/Microsoft.AspNetCore.Razor.Runtime/Internal/TaskCache.cs new file mode 100644 index 0000000000..c10fd7852e --- /dev/null +++ b/src/Microsoft.AspNetCore.Razor.Runtime/Internal/TaskCache.cs @@ -0,0 +1,24 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. + +using System.Threading.Tasks; + +namespace Microsoft.AspNetCore.Razor.Internal +{ + public static class TaskCache + { + + /// + /// A that's already completed successfully. + /// + /// + /// We're caching this in a static readonly field to make it more inlinable and avoid the volatile lookup done + /// by Task.CompletedTask. + /// +#if NET451 + public static readonly Task CompletedTask = Task.FromResult(0); +#else + public static readonly Task CompletedTask = Task.CompletedTask; +#endif + } +} \ No newline at end of file diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs index aa826dbbd5..fda0854e62 100644 --- a/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs +++ b/src/Microsoft.AspNetCore.Razor.Runtime/Runtime/TagHelpers/TagHelperExecutionContext.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Text.Encodings.Web; using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Internal; using Microsoft.AspNetCore.Razor.TagHelpers; namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers @@ -31,7 +32,7 @@ namespace Microsoft.AspNetCore.Razor.Runtime.TagHelpers tagMode, items: new Dictionary(), uniqueId: string.Empty, - executeChildContentAsync: async () => await Task.FromResult(result: true), + executeChildContentAsync: () => TaskCache.CompletedTask, startTagHelperWritingScope: _ => { }, endTagHelperWritingScope: () => new DefaultTagHelperContent()) { diff --git a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelper.cs b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelper.cs index df82eb3797..bd1dd4d4b3 100644 --- a/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelper.cs +++ b/src/Microsoft.AspNetCore.Razor.Runtime/TagHelpers/TagHelper.cs @@ -2,6 +2,7 @@ // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System.Threading.Tasks; +using Microsoft.AspNetCore.Razor.Internal; namespace Microsoft.AspNetCore.Razor.TagHelpers { @@ -37,11 +38,10 @@ namespace Microsoft.AspNetCore.Razor.TagHelpers /// A stateful HTML element used to generate an HTML tag. /// A that on completion updates the . /// By default this calls into .. -#pragma warning disable 1998 - public virtual async Task ProcessAsync(TagHelperContext context, TagHelperOutput output) + public virtual Task ProcessAsync(TagHelperContext context, TagHelperOutput output) { Process(context, output); + return TaskCache.CompletedTask; } -#pragma warning restore 1998 } } \ No newline at end of file