You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Analyzer proposal: Use String.Contains(char) instead of String.Contains(String) #47180
Seems pretty straightforward. There was a previous effort to manually replace instances of String.Contains(string) with String.Contains(char), so an analyzer should automatically find any new instances for us from now on.
Suggested severity: Warning
Suggested category: Performance
Suggested milestone: Future (but we welcome contributions for 6.0)
Analyzer size: Small
Fixer size: Small
Should cover all overloads, and only where a literal is passed as argument:
This as proposed is not a breaking change, but we need to take care if we extend this analyzer to other methods (IndexOf, etc.). Switching from string to char in those methods is an observable behavioral change.
IMO, analyzers reporting performance issues should never be a warning by default in the .NET SDK, even if we expect no false positives. Only critical functional or security issues should be candidate for being warnings by default.
@mavasani that makes sense to me, i will keep that in mind while triaging
I have the fixes ready for runtime locally - it's just one that would actually surface for consumers and another one in testing/infrastructure code. It's pretty late in Germany so I hope y'all can live with me opening up the PR tomorrow 😊
Should I open a separate issue for that in runtime or is it okay to just throw them the PR?
Activity
mavasani commentedon Jan 19, 2021
Tagging @carlossanlop @buyaa-n - .NET API analyzer suggestion.
carlossanlop commentedon Jan 22, 2021
Seems pretty straightforward. There was a previous effort to manually replace instances of
String.Contains(string)withString.Contains(char), so an analyzer should automatically find any new instances for us from now on.Suggested severity: Warning
Suggested category: Performance
Suggested milestone: Future (but we welcome contributions for 6.0)
Analyzer size: Small
Fixer size: Small
Should cover all overloads, and only where a literal is passed as argument:
GrabYourPitchforks commentedon Jan 26, 2021
This as proposed is not a breaking change, but we need to take care if we extend this analyzer to other methods (
IndexOf, etc.). Switching from string to char in those methods is an observable behavioral change.21 remaining items
buyaa-n commentedon Mar 3, 2021
@mavasani that makes sense to me, i will keep that in mind while triaging
buyaa-n commentedon Mar 3, 2021
@stephentoub do we want to fix the warnings found in runtime? Sounds like we need to do
ifdeffor multitargeted buildsMeikTranel commentedon Mar 3, 2021
I have the fixes ready for runtime locally - it's just one that would actually surface for consumers and another one in testing/infrastructure code. It's pretty late in Germany so I hope y'all can live with me opening up the PR tomorrow 😊
Should I open a separate issue for that in runtime or is it okay to just throw them the PR?
buyaa-n commentedon Mar 3, 2021
Thanks, @MeikTranel, sounds good, i don't think we need an issue with that, you can reference this issue in your PR
Use string.Contains(char) wherever possible - fallback to IndexOf if …
stephentoub commentedon Jul 13, 2021
This was implemented as CA1847. Thanks!
xtqqczze commentedon Jul 13, 2021
Fixed by dotnet/roslyn-analyzers#4908.