Skip to content
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

Call simpler overloads of Substring and Slice #68937

Merged
merged 1 commit into from
May 11, 2022

Conversation

GrabYourPitchforks
Copy link
Member

@GrabYourPitchforks GrabYourPitchforks commented May 5, 2022

Minor code simplification which looks for places where we have code utilizing one of the following patterns:

someString.Substring(newOffset, someString.Length - newOffset);
someSpan.Slice(newOffset, someSpan.Length - newOffset);

And calls the single-parameter overload instead:

someString.Substring(newOffset);
someSpan.Slice(newOffset);

In particular, I did not try to improve the perf of the call sites, such as changing from an allocating call to an allocation-free call, etc. This is just a code simplification and doesn't try to change any of the logic.

@ghost
Copy link

ghost commented May 5, 2022

Tagging subscribers to this area: @dotnet/area-meta
See info in area-owners.md if you want to be subscribed.

Issue Details

Minor code simplification which looks for places where we have code utilizing one of the following patterns:

someString.Substring(newOffset, someString.Length - newOffset);
someSpan.Slice(newOffset, someSpan.Length - newOffset);

And calls the single-parameter overload instead:

someString.Substring(newOffset);
someSpan.Slice(newOffset);
Author: GrabYourPitchforks
Assignees: -
Labels:

area-Meta

Milestone: -

@stephentoub
Copy link
Member

Looks like fodder for another analyzer.

@GrabYourPitchforks
Copy link
Member Author

GrabYourPitchforks commented May 6, 2022

Looks like fodder for another analyzer.

Pondered that while doing this, but it's not really a perf gain. It's more of a code readability thing. Do we have good examples of analyzers in that category today?

Edit: I put up the analyzer proposal. I submit to the mercy of the analyzer gods to hash it out. :)

@GrabYourPitchforks
Copy link
Member Author

/azp run runtime

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@GrabYourPitchforks
Copy link
Member Author

CI failures are known issue #68939.

@GrabYourPitchforks GrabYourPitchforks merged commit 52fd1a5 into dotnet:main May 11, 2022
@GrabYourPitchforks GrabYourPitchforks deleted the span_substr branch May 11, 2022 06:23
@ghost ghost locked as resolved and limited conversation to collaborators Jun 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants