Eliminate redundant isValid check from DefaultEndpointSelector.ProcessFinalCandidates(...). (#881)

This commit is contained in:
Gert Driesen 2018-10-22 23:20:30 +02:00 committed by James Newton-King
parent 26e5ea3274
commit c93e3a76ff
1 changed files with 8 additions and 4 deletions

View File

@ -75,16 +75,20 @@ namespace Microsoft.AspNetCore.Routing.Matching
int? foundScore = null; int? foundScore = null;
for (var i = 0; i < candidateSet.Count; i++) for (var i = 0; i < candidateSet.Count; i++)
{ {
if (!candidateSet.IsValidCandidate(i))
{
continue;
}
ref var state = ref candidateSet[i]; ref var state = ref candidateSet[i];
var isValid = candidateSet.IsValidCandidate(i); if (foundScore == null)
if (isValid && foundScore == null)
{ {
// This is the first match we've seen - speculatively assign it. // This is the first match we've seen - speculatively assign it.
endpoint = state.Endpoint; endpoint = state.Endpoint;
values = state.Values; values = state.Values;
foundScore = state.Score; foundScore = state.Score;
} }
else if (isValid && foundScore < state.Score) else if (foundScore < state.Score)
{ {
// This candidate is lower priority than the one we've seen // This candidate is lower priority than the one we've seen
// so far, we can stop. // so far, we can stop.
@ -92,7 +96,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
// Don't worry about the 'null < state.Score' case, it returns false. // Don't worry about the 'null < state.Score' case, it returns false.
break; break;
} }
else if (isValid && foundScore == state.Score) else if (foundScore == state.Score)
{ {
// This is the second match we've found of the same score, so there // This is the second match we've found of the same score, so there
// must be an ambiguity. // must be an ambiguity.