Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void Setup()

for (var i = 0; i < _strings.Length; i++)
{
_segments[i] = new PathSegment(0, _strings[i].Length);
_segments[i] = new PathSegment(1, _strings[i].Length - 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be - 1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I attempted to trim one from the start and one from the end but I don't suppose it matters too much as long as it's a substring.

}

var samples = new int[Count];
Expand All @@ -39,7 +39,9 @@ public void Setup()
var entries = new List<(string text, int _)>();
for (var i = 0; i < samples.Length; i++)
{
entries.Add((_strings[samples[i]], i));
var sampleIndex = samples[i];
var segment = _segments[sampleIndex];
entries.Add((_strings[sampleIndex].Substring(segment.Start, segment.Length), i));
}

_linearSearch = new LinearSearchJumpTable(0, -1, entries.ToArray());
Expand Down
6 changes: 4 additions & 2 deletions src/Http/Routing/src/Matching/DictionaryJumpTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ internal sealed class DictionaryJumpTable : JumpTable
private readonly int _defaultDestination;
private readonly int _exitDestination;
private readonly FrozenDictionary<string, int> _dictionary;
private readonly FrozenDictionary<string, int>.AlternateLookup<ReadOnlySpan<char>> _lookup;

public DictionaryJumpTable(
int defaultDestination,
Expand All @@ -22,6 +23,7 @@ public DictionaryJumpTable(
_exitDestination = exitDestination;

_dictionary = entries.ToFrozenDictionary(e => e.text, e => e.destination, StringComparer.OrdinalIgnoreCase);
_lookup = _dictionary.GetAlternateLookup<ReadOnlySpan<char>>();
}

public override int GetDestination(string path, PathSegment segment)
Expand All @@ -31,8 +33,8 @@ public override int GetDestination(string path, PathSegment segment)
return _exitDestination;
}

var text = path.Substring(segment.Start, segment.Length);
if (_dictionary.TryGetValue(text, out var destination))
var text = path.AsSpan(segment.Start, segment.Length);
if (_lookup.TryGetValue(text, out var destination))
{
return destination;
}
Expand Down
Loading