8016324: filter/flatMap pipeline sinks should pass size information to downstream sink
Reviewed-by: chegar, mduigou
Contributed-by: Brian Goetz <brian.goetz@oracle.com>
--- a/jdk/src/share/classes/java/util/stream/DoublePipeline.java Thu Jun 20 10:45:46 2013 +0200
+++ b/jdk/src/share/classes/java/util/stream/DoublePipeline.java Thu Jun 20 11:02:28 2013 +0200
@@ -258,6 +258,12 @@
@Override
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble(sink) {
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(double t) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
DoubleStream result = mapper.apply(t);
@@ -290,6 +296,11 @@
Sink<Double> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedDouble(sink) {
@Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(double t) {
if (predicate.test(t))
downstream.accept(t);
--- a/jdk/src/share/classes/java/util/stream/IntPipeline.java Thu Jun 20 10:45:46 2013 +0200
+++ b/jdk/src/share/classes/java/util/stream/IntPipeline.java Thu Jun 20 11:02:28 2013 +0200
@@ -294,6 +294,12 @@
@Override
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
return new Sink.ChainedInt(sink) {
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(int t) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
IntStream result = mapper.apply(t);
@@ -326,6 +332,11 @@
Sink<Integer> opWrapSink(int flags, Sink<Integer> sink) {
return new Sink.ChainedInt(sink) {
@Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(int t) {
if (predicate.test(t))
downstream.accept(t);
--- a/jdk/src/share/classes/java/util/stream/LongPipeline.java Thu Jun 20 10:45:46 2013 +0200
+++ b/jdk/src/share/classes/java/util/stream/LongPipeline.java Thu Jun 20 11:02:28 2013 +0200
@@ -275,6 +275,12 @@
@Override
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedLong(sink) {
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(long t) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
LongStream result = mapper.apply(t);
@@ -307,6 +313,11 @@
Sink<Long> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedLong(sink) {
@Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(long t) {
if (predicate.test(t))
downstream.accept(t);
--- a/jdk/src/share/classes/java/util/stream/ReferencePipeline.java Thu Jun 20 10:45:46 2013 +0200
+++ b/jdk/src/share/classes/java/util/stream/ReferencePipeline.java Thu Jun 20 11:02:28 2013 +0200
@@ -166,6 +166,11 @@
Sink<P_OUT> opWrapSink(int flags, Sink<P_OUT> sink) {
return new Sink.ChainedReference<P_OUT>(sink) {
@Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(P_OUT u) {
if (predicate.test(u))
downstream.accept(u);
@@ -252,6 +257,12 @@
@Override
Sink<P_OUT> opWrapSink(int flags, Sink<R> sink) {
return new Sink.ChainedReference<P_OUT>(sink) {
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(P_OUT u) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
Stream<? extends R> result = mapper.apply(u);
@@ -273,6 +284,12 @@
Sink<P_OUT> opWrapSink(int flags, Sink<Integer> sink) {
return new Sink.ChainedReference<P_OUT>(sink) {
IntConsumer downstreamAsInt = downstream::accept;
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(P_OUT u) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
IntStream result = mapper.apply(u);
@@ -294,6 +311,12 @@
Sink<P_OUT> opWrapSink(int flags, Sink<Double> sink) {
return new Sink.ChainedReference<P_OUT>(sink) {
DoubleConsumer downstreamAsDouble = downstream::accept;
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(P_OUT u) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
DoubleStream result = mapper.apply(u);
@@ -315,6 +338,12 @@
Sink<P_OUT> opWrapSink(int flags, Sink<Long> sink) {
return new Sink.ChainedReference<P_OUT>(sink) {
LongConsumer downstreamAsLong = downstream::accept;
+ @Override
+ public void begin(long size) {
+ downstream.begin(-1);
+ }
+
+ @Override
public void accept(P_OUT u) {
// We can do better that this too; optimize for depth=0 case and just grab spliterator and forEach it
LongStream result = mapper.apply(u);