Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TrivialMatcher.cs « Matching « Microbenchmarks « perf « Routing « Http « src - github.com/dotnet/aspnetcore.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 775e81c544ff94f90824fd1b81b7daeae5f20392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Http.Features;

namespace Microsoft.AspNetCore.Routing.Matching;

// A test-only matcher implementation - used as a baseline for simpler
// perf tests. The idea with this matcher is that we can cheat on the requirements
// to establish a lower bound for perf comparisons.
internal sealed class TrivialMatcher : Matcher
{
    private readonly RouteEndpoint _endpoint;
    private readonly Candidate[] _candidates;

    public TrivialMatcher(RouteEndpoint endpoint)
    {
        _endpoint = endpoint;

        _candidates = new Candidate[] { new Candidate(endpoint), };
    }

    public sealed override Task MatchAsync(HttpContext httpContext)
    {
        if (httpContext == null)
        {
            throw new ArgumentNullException(nameof(httpContext));
        }

        var path = httpContext.Request.Path.Value;
        if (string.Equals(_endpoint.RoutePattern.RawText, path, StringComparison.OrdinalIgnoreCase))
        {
            httpContext.SetEndpoint(_endpoint);
            httpContext.Request.RouteValues = new RouteValueDictionary();
        }

        return Task.CompletedTask;
    }

    // This is here so this can be tested alongside DFA matcher.
    internal Candidate[] FindCandidateSet(string path, ReadOnlySpan<PathSegment> segments)
    {
        if (string.Equals(_endpoint.RoutePattern.RawText, path, StringComparison.OrdinalIgnoreCase))
        {
            return _candidates;
        }

        return Array.Empty<Candidate>();
    }
}