-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Expand small value sets to all case permutations in SearchValues<string> #98902
Expand small value sets to all case permutations in SearchValues<string> #98902
Conversation
Tagging subscribers to this area: @dotnet/area-system-buffers Issue DetailsImplements #98791 (comment) If we have a set of values like This optimization is a bit niche (unlikely to be applicable often), but it's really cheap to check whether it could apply, and can help cases with many non-letter characters in their prefixes. public class IgnoreCaseToOrdinal
{
private static readonly SearchValues<string> s_values = SearchValues.Create(["ab", "c!"], StringComparison.OrdinalIgnoreCase);
private readonly string _text = new('\n', 1000);
[Benchmark]
public int IndexOfAny() => _text.AsSpan().IndexOfAny(s_values);
}
|
src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs
Show resolved
Hide resolved
src/libraries/System.Private.CoreLib/src/System/SearchValues/Strings/StringSearchValues.cs
Show resolved
Hide resolved
54e8e3d
to
ac5966c
Compare
Implements #98791 (comment)
If we have a set of values like
["ab", "c!"]
, we can expand it to["ab", "Ab" "aB", "AB", "c!", "C!"]
and switch to case-sensitive searching.As long as we're making use of buckets that would otherwise have been empty, this is going to be an improvement as the prefix search loop is a bit simpler due to not needing to deal with casing. In the below benchmark, it means eliminating this step from the loop.
This optimization is a bit niche (unlikely to be applicable often), but it's really cheap to check whether it could apply, and can help cases with many non-letter characters in their prefixes.