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
Prefer string.AsSpan() over string.Substring() when parsing #33784
The rule should flag instances of a pattern like int.Parse(str.Substring(...)) and instead switch to using the span-based int.Parse(str.AsSpan(...)). This would apply to all of the primitive types, and more generally potentially anything that has an overload taking a ReadOnlySpan<char> instead of a string.
Seems reasonable. We should figure out how much we want our analyzers (especially our on-by-default analyzers) to push people into using span. Using ROS<char> increases the concept count for scenarios which are currently very simple.
@Mrnikbobjeff also approved in case you already started working on this. Let us know if you'd like to get this issue assigned to you.
I am currently working on porting my analyzers to be IOperation analyzers to be inline with the pattern already established. While I have a working implementation for a c# analyzer and fixer I still need to port the analyzer at least for this to be viable.
I closed #33778 in favor of this one (it was an identical approved proposal).
Note to whoever decides to work on this: Please take a look at this comment in the dup issue, since it contains a list of cases this analyzer should be able to address.
How does one enable this AsSpan diagnostics for netstandard2.0+ for using it over Substring?
Edit: It seems that the rule does not flag all uses of string.Substring, I would like all uses to get a diagnostic for replacing it with AsSpan as it will increase my program's performance indirectly, yes in some cases my code makes substrings and assigns them to variables before passing them to methods and so the AsSpan version could help me greatly in that case.
Activity
jeffhandley commentedon Mar 21, 2020
Estimates:
GrabYourPitchforks commentedon Nov 10, 2020
Seems reasonable. We should figure out how much we want our analyzers (especially our on-by-default analyzers) to push people into using span. Using
ROS<char>increases the concept count for scenarios which are currently very simple.bartonjs commentedon Nov 10, 2020
Video
Category: Performance
Suggested severity: Info
carlossanlop commentedon Nov 10, 2020
@Mrnikbobjeff also approved in case you already started working on this. Let us know if you'd like to get this issue assigned to you.
Mrnikbobjeff commentedon Nov 11, 2020
I am currently working on porting my analyzers to be IOperation analyzers to be inline with the pattern already established. While I have a working implementation for a c# analyzer and fixer I still need to port the analyzer at least for this to be viable.
carlossanlop commentedon Nov 20, 2020
Would you like me to assign this to you @Mrnikbobjeff or should i mark it up-for-grabs instead?
carlossanlop commentedon Feb 5, 2021
I closed #33778 in favor of this one (it was an identical approved proposal).
Note to whoever decides to work on this: Please take a look at this comment in the dup issue, since it contains a list of cases this analyzer should be able to address.
NewellClark commentedon Feb 6, 2021
I would like to be assigned to this. I'll start work on it immediately.
AraHaan commentedon Apr 12, 2021
How does one enable this
AsSpandiagnostics for netstandard2.0+ for using it overSubstring?Edit: It seems that the rule does not flag all uses of
string.Substring, I would like all uses to get a diagnostic for replacing it withAsSpanas it will increase my program's performance indirectly, yes in some cases my code makes substrings and assigns them to variables before passing them to methods and so theAsSpanversion could help me greatly in that case.