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

Optimize the generic string.Join for length 1 collections#6463

Merged
jkotas merged 5 commits into
dotnet:masterfrom
jamesqo:generic-join-optimization
Jul 27, 2016
Merged

Optimize the generic string.Join for length 1 collections#6463
jkotas merged 5 commits into
dotnet:masterfrom
jamesqo:generic-join-optimization

Conversation

@jamesqo
Copy link
Copy Markdown

@jamesqo jamesqo commented Jul 25, 2016

I noticed an optimization made by @bbowyersmyth for Join some time ago for single-item lists-- (#1460) but it looks like it wasn't done for the generic version. The one that accepts an IEnumerable<T> is a little trickier to optimize since you need to handle the fact that either currentValue or its ToString could be null, but here it is.

Notes:

  • I took extra care to keep the virtual method call order consistent-- everything is called in the order MoveNext / Current / ToString, in case for some bizarre reason one of the latter 2 modify state.
  • I also saw what appeared to be some dead code somewhere else in String (private consts that are not used anywhere), so I removed that.

CoreFX tests already exist for this overload, including for objects with ToString returning null.

cc @jkotas @bbowyersmyth @AlexGhiondea

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.

Nit: Could save a local and declare T currentValue here

@bbowyersmyth
Copy link
Copy Markdown

Some minor comments. LGTM

@jamesqo
Copy link
Copy Markdown
Author

jamesqo commented Jul 26, 2016

@bbowyersmyth Thanks for the feedback! I've pushed another commit that fixes the nits.

@adityamandaleeka
Copy link
Copy Markdown
Member

The Ubuntu failure is issue #6222.

@adityamandaleeka
Copy link
Copy Markdown
Member

@dotnet-bot test Ubuntu x64 Checked Build and Test

@jamesqo
Copy link
Copy Markdown
Author

jamesqo commented Jul 27, 2016

@jkotas PTAL

@adityamandaleeka Thank you for restarting the CI.

@adityamandaleeka
Copy link
Copy Markdown
Member

LGTM. The Ubuntu CI failed again with #6222.

@jkotas jkotas merged commit dcd9aae into dotnet:master Jul 27, 2016
@jamesqo jamesqo deleted the generic-join-optimization branch July 27, 2016 20:27
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
…eclr#6463)

* Optimize the generic string.Join for length 1 collections
* Keep the call order consistent: MoveNext-Current-ToString
* Convert to do..while loop to reduce code duplication

Commit migrated from dotnet/coreclr@dcd9aae
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