Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Avoid unnecessary Span to ReadOnlySpan casts #34646

Merged
merged 1 commit into from
Jan 17, 2019

Conversation

stephentoub
Copy link
Member

In a bunch of places we're creating a Span only to then cast it (generally implicitly) to a ReadOnlySpan. While the JIT is generally able to do the RightThing(tm), we can avoid the unnecessary IL and pressure on the JIT by just creating a ReadOnlySpan to begin with.

Also cleaned up a few other minor span-related things as I was auditing, e.g. new Span(…).Slice(…) vs .AsSpan(…).

cc: @jkotas

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

In a bunch of places we're creating a Span only to then cast it (generally implicitly) to a ReadOnlySpan.  While the JIT is generally able to do the RightThing(tm), we can avoid the unnecessary IL and pressure on the JIT by just creating a ReadOnlySpan to begin with.
@stephentoub stephentoub merged commit ab92553 into dotnet:master Jan 17, 2019
@stephentoub stephentoub deleted the spancasts branch January 17, 2019 20:13
@karelz karelz added this to the 3.0 milestone Mar 18, 2019
JRahnama pushed a commit to JRahnama/SqlClient that referenced this pull request Sep 5, 2019
…nlySpan casts

Port GitHub PR 34646: Avoid unnecessary Span to ReadOnlySpan casts

dotnet/corefx#34646
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
In a bunch of places we're creating a Span only to then cast it (generally implicitly) to a ReadOnlySpan.  While the JIT is generally able to do the RightThing(tm), we can avoid the unnecessary IL and pressure on the JIT by just creating a ReadOnlySpan to begin with.

Commit migrated from dotnet/corefx@ab92553
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants