-
Notifications
You must be signed in to change notification settings - Fork 10.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change JumpTable to take ReadOnlySpan #22397
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using System; | ||
|
@@ -29,14 +29,14 @@ public DictionaryJumpTable( | |
} | ||
} | ||
|
||
public override int GetDestination(string path, PathSegment segment) | ||
public override int GetDestination(ReadOnlySpan<char> path) | ||
{ | ||
if (segment.Length == 0) | ||
if (path.Length == 0) | ||
{ | ||
return _exitDestination; | ||
} | ||
|
||
var text = path.Substring(segment.Start, segment.Length); | ||
var text = path.ToString(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @GrabYourPitchforks @stephentoub @jkotas it would be great to allow lookup by There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes. The sticking point has been with a design regarding custom comparers: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One other sticking point is that there's no guarantee that the same algorithm is used to compute the hash code of a Edit: The reason this matters is that the hash code is needed to compute which bucket the key maps to. If we inadvertently compute the wrong hash code, we could end up in a situation where the dictionary truly does contain some There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I get it but how do we make progress? Does somebody just have to ask again? Do we have proposals? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My proposal is what's in my linked comment: throw from the method if the comparer being used is not one we implicitly understand and can handle internally appropriately. It's not perfect, it's not beautiful, but it addresses what I think is the 99% case: using one of the built-in comparers. The downside is there's a big cliff that manifests as either an exception or string allocation when the comparer isn't supported. If we went with exception, we could make it work in the future if we added another interface supporting spans we could query for. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There are a few candidate proposals in dotnet/runtime#27229. (But Steve, I don't see your idea reflected there? Maybe I'm looking at the wrong piece?) The issue is currently marked as needs work and has no assignee. Somebody would need to champion it and drive it through API review. |
||
if (_dictionary.TryGetValue(text, out var destination)) | ||
{ | ||
return destination; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused