Skip to content

Call simpler overloads of Substring and Slice - #68937

Merged
GrabYourPitchforks merged 1 commit into
dotnet:mainfrom
GrabYourPitchforks:span_substr
May 11, 2022
Merged

GrabYourPitchforks merged 1 commit into
dotnet:mainfrom
GrabYourPitchforks:span_substr

Conversation

@GrabYourPitchforks

@GrabYourPitchforks GrabYourPitchforks commented May 5, 2022 •

Copy link
Copy Markdown
Member

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

ghost commented May 5, 2022

Copy link
Copy Markdown

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
Copy Markdown
Member

Looks like fodder for another analyzer.

@GrabYourPitchforks

GrabYourPitchforks commented May 6, 2022 •

Copy link
Copy Markdown
Member Author

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
Copy Markdown
Member Author

/azp run runtime

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@GrabYourPitchforks

Copy link
Copy Markdown
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