-
Couldn't load subscription status.
- Fork 6.1k
8072840: Add a method to Collector that returns a sized supplying mutable result container #23461
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
Conversation
|
👋 Welcome back fmeum! A progress list of the required criteria for merging this PR into |
|
❗ This change is not yet ready to be integrated. |
376ea9b to
dc06e2d
Compare
01828ad to
f9d9312
Compare
Demo of Guava changes for openjdk/jdk#23461. This change pre-sizes collectors for which the size of the output collection must match the size of the input stream. It omits cases like `ImmutableSet` (which deduplicates), but it includes cases `ImmutableList` (obviously) and `ImmutableMap`/`ImmutableBiMap` (which rejects duplicate keys). RELNOTES=`collect`: Changed `toImmutableList`, `toImmutableMap`, and `toImmutableBiMap` to internally pre-size their collections when possible. PiperOrigin-RevId: 725756865
Demo of Guava changes for openjdk/jdk#23461. This change pre-sizes collectors for which the size of the output collection must match the size of the input stream. It omits cases like `ImmutableSet` (which deduplicates), but it includes cases `ImmutableList` (obviously) and `ImmutableMap`/`ImmutableBiMap` (which rejects duplicate keys). RELNOTES=`collect`: Changed `toImmutableList`, `toImmutableMap`, and `toImmutableBiMap` to internally pre-size their collections when possible. PiperOrigin-RevId: 725756865
|
@fmeum This pull request has been inactive for more than 8 weeks and will be automatically closed if another 8 weeks passes without any activity. To avoid this, simply add a new comment to the pull request. Feel free to ask for assistance if you need help with progressing this pull request towards integration! |
|
@fmeum This pull request has been inactive for more than 16 weeks and will now be automatically closed. If you would like to continue working on this pull request in the future, feel free to reopen it! This can be done using the |
This changes introduces a new
LongFunction<A> sizedSupplier()method onCollectorthat is passed the exact size of the stream if known and-1else. This can greatly reduces the amount of allocations and copying for streams that reshape data structures rather than perform extensive computations.For convenience,
Collector.ofSizedfactory methods are added that accept an additionalIntFunction<A>that is called instead of the providedSupplier<A>if the stream size is known. Data structures that can have sizes that don't fit in anintcan still use the new feature by providing their own implementation ofCollector.The default implementation of
sizedSupplierreturns a function that ignores its argument and always returnssupplier().get(). ExistingCollectorimplementations outside the standard library can adoptsizedSupplierwhile remaining backwards compatible with older JDKs by overriding the method without an@Overrideannotation.Existing collectors in
Collectorsare updated to use the new functionality if the final size of the collection can be determined from the stream size (e.g.toMapwithout a merge function does, buttoSetdoesn't). For this purpose, a new constructor accepting an initial capacity is added toStringJoiner.Progress
Issue
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/23461/head:pull/23461$ git checkout pull/23461Update a local copy of the PR:
$ git checkout pull/23461$ git pull https://git.openjdk.org/jdk.git pull/23461/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 23461View PR using the GUI difftool:
$ git pr show -t 23461Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/23461.diff