-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Add ContainsAny{Except} #87621
Add ContainsAny{Except} #87621
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @dotnet/area-system-memory Issue DetailsContributes to #86528 ( This PR adds
|
@@ -401,6 +396,192 @@ public static ReadOnlyMemory<char> AsMemory(this string? text, Range range) | |||
return SpanHelpers.Contains(ref MemoryMarshal.GetReference(span), value, span.Length); | |||
} | |||
|
|||
/// <inheritdoc cref="ContainsAny{T}(ReadOnlySpan{T}, T, T)"/> | |||
[MethodImpl(MethodImplOptions.AggressiveInlining)] |
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.
Are all of these AggressiveInlinings actually needed?
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.
Probably not everywhere, but it felt like they shouldn't hurt anything here. The intent at least is for these to be inlined such that anything interesting in IndexOfAny
can be removed after inlining.
It'd be a bit sad if the JIT gave up on any of these because of the extra indirection.
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.
@EgorBo, what should our approach here be in general?
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.
I'd be surprised to see it non-inlined, although, this will never be inlined even with the Aggressive attribute for shared T due to runtime lookup
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.
Do we want to be in the habit of annotating everything as AggressiveInlining we want inlined even if should be anyway?
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.
Do we want to be in the habit of annotating everything as AggressiveInlining we want inlined even if should be anyway?
I am not a fan of that approach as it offends the jit 😄 although, we have other runtimes. I can probably run some script to find methods <= 16 bytes of IL with AggressiveInlining just out of curiosity (JIT always inlines methods <= 16 bytes of IL so the attribute is basically no-op)
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.
E.g. I think in Java they don't even have such an attribute!
src/libraries/System.Private.CoreLib/src/System/MemoryExtensions.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs
Outdated
Show resolved
Hide resolved
src/libraries/System.IO.Pipes/src/System/IO/Pipes/PipeStream.Unix.cs
Outdated
Show resolved
Hide resolved
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.
Thanks
) * Update dependencies from https://github.com/dotnet/aspnetcore build 20230621.15 Microsoft.AspNetCore.App.Runtime.win-x64 , Microsoft.AspNetCore.Mvc.Testing , Microsoft.AspNetCore.TestHost , Microsoft.Extensions.Caching.StackExchangeRedis , Microsoft.Extensions.Diagnostics.HealthChecks , Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions , Microsoft.Extensions.Features , Microsoft.Extensions.Http.Polly , Microsoft.Extensions.ObjectPool From Version 8.0.0-preview.6.23315.13 -> To Version 8.0.0-preview.6.23321.15 Dependency coherency updates Microsoft.Bcl.TimeProvider,Microsoft.Extensions.Caching.Abstractions,Microsoft.Extensions.Caching.Memory,Microsoft.Extensions.Configuration.Abstractions,Microsoft.Extensions.Configuration.Binder,Microsoft.Extensions.Configuration.CommandLine,Microsoft.Extensions.Configuration.Json,Microsoft.Extensions.Configuration,Microsoft.Extensions.DependencyInjection.Abstractions,Microsoft.Extensions.DependencyInjection,Microsoft.Extensions.Hosting.Abstractions,Microsoft.Extensions.Hosting,Microsoft.Extensions.Http,Microsoft.Extensions.Logging.Abstractions,Microsoft.Extensions.Logging.Configuration,Microsoft.Extensions.Logging.Console,Microsoft.Extensions.Logging,Microsoft.Extensions.Options.ConfigurationExtensions,Microsoft.Extensions.Options.DataAnnotations,Microsoft.Extensions.Options,Microsoft.Extensions.Primitives,System.Collections.Immutable,System.Configuration.ConfigurationManager,System.Diagnostics.DiagnosticSource,System.Diagnostics.PerformanceCounter,System.IO.Hashing,System.Net.Http.Json,System.Security.Cryptography.Pkcs,System.Security.Cryptography.Xml,System.Text.Encodings.Web,System.Text.Json,System.Runtime.Caching From Version 8.0.0-preview.6.23314.15 -> To Version 8.0.0-preview.6.23318.9 (parent: Microsoft.AspNetCore.App.Runtime.win-x64 * Bump the SDK to resolve the break caused by dotnet/runtime#87621 * Update local copy of ExperimentalAttribute per dotnet/runtime#85444 * Update dependencies from https://github.com/dotnet/aspnetcore build 20230623.8 Microsoft.AspNetCore.App.Runtime.win-x64 , Microsoft.AspNetCore.Mvc.Testing , Microsoft.AspNetCore.TestHost , Microsoft.Extensions.Caching.StackExchangeRedis , Microsoft.Extensions.Diagnostics.HealthChecks , Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions , Microsoft.Extensions.Features , Microsoft.Extensions.Http.Polly , Microsoft.Extensions.ObjectPool From Version 8.0.0-preview.6.23315.13 -> To Version 8.0.0-preview.6.23323.8 Dependency coherency updates Microsoft.Bcl.TimeProvider,Microsoft.Extensions.Caching.Abstractions,Microsoft.Extensions.Caching.Memory,Microsoft.Extensions.Configuration.Abstractions,Microsoft.Extensions.Configuration.Binder,Microsoft.Extensions.Configuration.CommandLine,Microsoft.Extensions.Configuration.Json,Microsoft.Extensions.Configuration,Microsoft.Extensions.DependencyInjection.Abstractions,Microsoft.Extensions.DependencyInjection,Microsoft.Extensions.Hosting.Abstractions,Microsoft.Extensions.Hosting,Microsoft.Extensions.Http,Microsoft.Extensions.Logging.Abstractions,Microsoft.Extensions.Logging.Configuration,Microsoft.Extensions.Logging.Console,Microsoft.Extensions.Logging,Microsoft.Extensions.Options.ConfigurationExtensions,Microsoft.Extensions.Options.DataAnnotations,Microsoft.Extensions.Options,Microsoft.Extensions.Primitives,System.Collections.Immutable,System.Configuration.ConfigurationManager,System.Diagnostics.DiagnosticSource,System.Diagnostics.PerformanceCounter,System.IO.Hashing,System.Net.Http.Json,System.Security.Cryptography.Pkcs,System.Security.Cryptography.Xml,System.Text.Encodings.Web,System.Text.Json,System.Runtime.Caching From Version 8.0.0-preview.6.23314.15 -> To Version 8.0.0-preview.6.23323.4 (parent: Microsoft.AspNetCore.App.Runtime.win-x64 * Update dependencies from https://github.com/dotnet/aspnetcore build 20230625.3 Microsoft.AspNetCore.App.Runtime.win-x64 , Microsoft.AspNetCore.Mvc.Testing , Microsoft.AspNetCore.TestHost , Microsoft.Extensions.Caching.StackExchangeRedis , Microsoft.Extensions.Diagnostics.HealthChecks , Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions , Microsoft.Extensions.Features , Microsoft.Extensions.Http.Polly , Microsoft.Extensions.ObjectPool From Version 8.0.0-preview.6.23315.13 -> To Version 8.0.0-preview.6.23325.3 Dependency coherency updates Microsoft.Bcl.TimeProvider,Microsoft.Extensions.Caching.Abstractions,Microsoft.Extensions.Caching.Memory,Microsoft.Extensions.Configuration.Abstractions,Microsoft.Extensions.Configuration.Binder,Microsoft.Extensions.Configuration.CommandLine,Microsoft.Extensions.Configuration.Json,Microsoft.Extensions.Configuration,Microsoft.Extensions.DependencyInjection.Abstractions,Microsoft.Extensions.DependencyInjection,Microsoft.Extensions.Hosting.Abstractions,Microsoft.Extensions.Hosting,Microsoft.Extensions.Http,Microsoft.Extensions.Logging.Abstractions,Microsoft.Extensions.Logging.Configuration,Microsoft.Extensions.Logging.Console,Microsoft.Extensions.Logging,Microsoft.Extensions.Options.ConfigurationExtensions,Microsoft.Extensions.Options.DataAnnotations,Microsoft.Extensions.Options,Microsoft.Extensions.Primitives,System.Collections.Immutable,System.Configuration.ConfigurationManager,System.Diagnostics.DiagnosticSource,System.Diagnostics.PerformanceCounter,System.IO.Hashing,System.Net.Http.Json,System.Security.Cryptography.Pkcs,System.Security.Cryptography.Xml,System.Text.Encodings.Web,System.Text.Json,System.Runtime.Caching From Version 8.0.0-preview.6.23314.15 -> To Version 8.0.0-preview.6.23323.4 (parent: Microsoft.AspNetCore.App.Runtime.win-x64 * Deprecate this repo's option validator code gen in favor of the runtime'src - This removes traces of the option code generator in this repo, now that the code has moved to dotnet/runtime. Unfortunately, the generator in dotnet/runtime has currently dropped the use of the 'file' visibility accessor in generated code, which leads to some conflicting type definitions in this code base due to the use of IntervalsVisibleTo. This surfaces as build warnings which are safe to ignore, since the C# compiler ends up binding to the right thing. Fixing these warnings will require a new drop of the runtime's generator. * Bump SDK * Suppress CS0436 --------- Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com> Co-authored-by: Igor Velikorossov <[email protected]> Co-authored-by: Martin Taillefer <[email protected]>
Contributes to #86528 (
SearchValues<string>
and-WhiteSpace
overloads remain as not yet implemented)This PR adds
ContainsAny
as a helper aroundIndexOfAny >= 0
.I left out potential optimizations (e.g. dedicated
Contains
paths forSearchValues
) for future PRs.