From 6a6bd3f0daa36151e25144cca2465eec3cc12580 Mon Sep 17 00:00:00 2001 From: James Newton-King Date: Wed, 13 Jun 2018 08:48:27 +1200 Subject: [PATCH] Refactor TreeMatcher to not use async (#552) --- .../Matchers/TreeMatcher.cs | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.AspNetCore.Routing/Matchers/TreeMatcher.cs b/src/Microsoft.AspNetCore.Routing/Matchers/TreeMatcher.cs index 36ae3b85e2..24149d0fa0 100644 --- a/src/Microsoft.AspNetCore.Routing/Matchers/TreeMatcher.cs +++ b/src/Microsoft.AspNetCore.Routing/Matchers/TreeMatcher.cs @@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers _cache.EnsureInitialized(); } - public override async Task MatchAsync(HttpContext httpContext, IEndpointFeature feature) + public override Task MatchAsync(HttpContext httpContext, IEndpointFeature feature) { if (httpContext == null) { @@ -94,7 +94,7 @@ namespace Microsoft.AspNetCore.Routing.Matchers continue; } - await SelectEndpointAsync(httpContext, feature, (MatcherEndpoint[])entry.Tag); + SelectEndpoint(httpContext, feature, (MatcherEndpoint[])entry.Tag); if (feature.Endpoint != null) { @@ -109,11 +109,15 @@ namespace Microsoft.AspNetCore.Routing.Matchers } } - return; + // Found a matching endpoint + return Task.CompletedTask; } } } } + + // No match found + return Task.CompletedTask; } private bool MatchConstraints( @@ -139,19 +143,9 @@ namespace Microsoft.AspNetCore.Routing.Matchers return true; } - private Task SelectEndpointAsync(HttpContext httpContext, IEndpointFeature feature, IReadOnlyList endpoints) + private void SelectEndpoint(HttpContext httpContext, IEndpointFeature feature, IReadOnlyList endpoints) { - MatcherEndpoint endpoint; - - try - { - endpoint = (MatcherEndpoint)_endpointSelector.SelectBestCandidate(httpContext, endpoints); - } - catch (Exception ex) - { - // Handle AmbiguousMatchException from EndpointSelector - return Task.FromException(ex); - } + var endpoint = (MatcherEndpoint)_endpointSelector.SelectBestCandidate(httpContext, endpoints); if (endpoint == null) { @@ -164,8 +158,6 @@ namespace Microsoft.AspNetCore.Routing.Matchers feature.Endpoint = endpoint; feature.Invoker = endpoint.Invoker; } - - return Task.CompletedTask; } private UrlMatchingTree[] CreateTrees(IReadOnlyList endpoints)