Skip to content

Commit 05c3bb5

Browse files
committed
PR feedback
1 parent d628ff1 commit 05c3bb5

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

src/Http/Routing/src/Matching/HttpMethodMatcherPolicy.cs

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -374,11 +374,25 @@ public PolicyJumpTable BuildJumpTable(int exitDestination, IReadOnlyList<PolicyJ
374374
{
375375
// If there is only a single valid HTTP method then use an optimized jump table.
376376
// It avoids unnecessary dictionary lookups with the method name.
377+
var httpMethodDestination = destinations.Single();
378+
var method = httpMethodDestination.Key;
379+
var destination = httpMethodDestination.Value;
380+
var supportsCorsPreflight = false;
381+
var corsPreflightDestination = 0;
382+
383+
if (corsPreflightDestinations?.Count > 0)
384+
{
385+
supportsCorsPreflight = true;
386+
corsPreflightDestination = corsPreflightDestinations.Single().Value;
387+
}
388+
377389
return new SingleEntryHttpMethodPolicyJumpTable(
378390
exitDestination,
379-
destinations,
391+
method,
392+
destination,
393+
supportsCorsPreflight,
380394
corsPreflightExitDestination,
381-
corsPreflightDestinations);
395+
corsPreflightDestination);
382396
}
383397
else
384398
{
@@ -454,21 +468,18 @@ private sealed class SingleEntryHttpMethodPolicyJumpTable : PolicyJumpTable
454468

455469
public SingleEntryHttpMethodPolicyJumpTable(
456470
int exitDestination,
457-
Dictionary<string, int> destinations,
471+
string method,
472+
int destination,
473+
bool supportsCorsPreflight,
458474
int corsPreflightExitDestination,
459-
Dictionary<string, int>? corsPreflightDestinations)
475+
int corsPreflightDestination)
460476
{
461477
_exitDestination = exitDestination;
478+
_method = method;
479+
_destination = destination;
480+
_supportsCorsPreflight = supportsCorsPreflight;
462481
_corsPreflightExitDestination = corsPreflightExitDestination;
463-
var destination = destinations.Single();
464-
_method = destination.Key;
465-
_destination = destination.Value;
466-
467-
if (corsPreflightDestinations?.Count > 0)
468-
{
469-
_supportsCorsPreflight = true;
470-
_corsPreflightDestination = corsPreflightDestinations.Single().Value;
471-
}
482+
_corsPreflightDestination = corsPreflightDestination;
472483
}
473484

474485
public override int GetDestination(HttpContext httpContext)

0 commit comments

Comments
 (0)