RFR: 8357647 : Stream gatherers forward upstream size information to downstream
Viktor Klang
vklang at openjdk.org
Fri May 23 16:08:52 UTC 2025
On Fri, 23 May 2025 15:53:22 GMT, Johannes Döbler <duke at openjdk.org> wrote:
>> While it could be argued that unbounded Spliterators should not report SIZED / SUBSIZED, GatherSink should report an unknown emission size, so switching to downstream.begin(-1) rather than downstream.begin(size).
>>
>> Includes a regression test which yields an OOME if this change is omitted.
>
> src/java.base/share/classes/java/util/stream/GathererOp.java line 153:
>
>> 151: if (initializer != Gatherer.defaultInitializer()) // Optimization
>> 152: state = initializer.get();
>> 153: sink.begin(-1); // GathererOp does not know the size of the output
>
> The Integrator of the SO question which motivated this PR _does_ know the size of the output. In general would it be worth to enhance Integrator with something like `default long estimateSize(long streamEstimate) { return -1; }` to allow Integrator implementations to weigh in?
@jdlib I guess that would depend on the definition of *value* and *cost* in this context.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/25418#discussion_r2104911643
More information about the core-libs-dev
mailing list