Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Use cached empty arrays for "".ToCharArray - #5504

Merged
jkotas merged 1 commit into
dotnet:masterfrom
jamesqo:empty-tochararray
Jun 7, 2016
Merged

jkotas merged 1 commit into
dotnet:masterfrom
jamesqo:empty-tochararray

Conversation

@jamesqo

@jamesqo jamesqo commented Jun 5, 2016

Copy link
Copy Markdown

Currently, if you do "".ToCharArray() it will always allocate a new array. I changed it to use Array.Empty<char> for CoreCLR, but fallback to the old behavior of returning a new array each time on the .NET Framework.

As we have to make the length check anyway (for fixed) I think this is basically a free perf gain.

cc: @AlexGhiondea @jkotas

Comment thread src/mscorlib/src/System/String.cs Outdated

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Any reason for combining the 2 fixed statements? I personally find it easier to read when each variable is in its own statement.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

No reason in particular; I'll change it back in a minute or two to multiple fixed statements.

@AlexGhiondea

Copy link
Copy Markdown

Thanks for fixing this!

@jamesqo
jamesqo force-pushed the empty-tochararray branch from 4c082c7 to 1ceb294 Compare June 6, 2016 22:18
@jkotas jkotas closed this Jun 7, 2016
@jkotas jkotas reopened this Jun 7, 2016
@jkotas
jkotas merged commit 8a8f26b into dotnet:master Jun 7, 2016
@jkotas

jkotas commented Jun 7, 2016

Copy link
Copy Markdown
Member

Could you please port the fix to CoreRT as well?

@jamesqo
jamesqo deleted the empty-tochararray branch June 7, 2016 17:34
jkotas pushed a commit to dotnet/corert that referenced this pull request Jun 7, 2016
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
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.

4 participants