changeset 7819:5ecb2472fcbf

Eliminate Node.flatten
author briangoetz
date Thu, 04 Apr 2013 20:18:30 -0400
parents 5a0b40214415
children e473df6aaa89
files src/share/classes/java/util/stream/AbstractPipeline.java src/share/classes/java/util/stream/DoublePipeline.java src/share/classes/java/util/stream/IntPipeline.java src/share/classes/java/util/stream/LongPipeline.java src/share/classes/java/util/stream/Node.java src/share/classes/java/util/stream/ReferencePipeline.java src/share/classes/java/util/stream/StreamOpFlag.java
diffstat 7 files changed, 8 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/util/stream/AbstractPipeline.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/AbstractPipeline.java	Thu Apr 04 20:18:30 2013 -0400
@@ -265,8 +265,7 @@
         // If the last intermediate operation is stateful then
         // evaluate directly to avoid an extra collection step
         if (isParallel() && previousStage != null && opIsStateful()) {
-            return opEvaluateParallel(previousStage, previousStage.sourceSpliterator(), generator)
-                    .flatten(generator);
+            return opEvaluateParallel(previousStage, previousStage.sourceSpliterator(), generator);
         }
         else {
             return evaluate(sourceSpliterator(), true, generator);
--- a/src/share/classes/java/util/stream/DoublePipeline.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/DoublePipeline.java	Thu Apr 04 20:18:30 2013 -0400
@@ -434,7 +434,8 @@
 
     @Override
     public final double[] toArray() {
-        return ((Node.OfDouble) evaluateToArrayNode(Double[]::new)).asDoubleArray();
+        return NodeUtils.doubleFlatten((Node.OfDouble) evaluateToArrayNode(Double[]::new))
+                        .asDoubleArray();
     }
 
     //
--- a/src/share/classes/java/util/stream/IntPipeline.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/IntPipeline.java	Thu Apr 04 20:18:30 2013 -0400
@@ -461,7 +461,8 @@
 
     @Override
     public final int[] toArray() {
-        return ((Node.OfInt) evaluateToArrayNode(Integer[]::new)).asIntArray();
+        return NodeUtils.intFlatten((Node.OfInt) evaluateToArrayNode(Integer[]::new))
+                        .asIntArray();
     }
 
 
--- a/src/share/classes/java/util/stream/LongPipeline.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/LongPipeline.java	Thu Apr 04 20:18:30 2013 -0400
@@ -444,7 +444,7 @@
 
     @Override
     public final long[] toArray() {
-        return ((Node.OfLong) evaluateToArrayNode(Long[]::new)).asLongArray();
+        return NodeUtils.longFlatten((Node.OfLong) evaluateToArrayNode(Long[]::new)).asLongArray();
     }
 
 
--- a/src/share/classes/java/util/stream/Node.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/Node.java	Thu Apr 04 20:18:30 2013 -0400
@@ -145,10 +145,6 @@
         return StreamShape.REFERENCE;
     }
 
-    default Node<T> flatten(IntFunction<T[]> generator) {
-        return NodeUtils.flatten(this, generator);
-    }
-
     /**
      * Returns the number of elements contained in this node
      *
@@ -301,10 +297,6 @@
             return StreamShape.INT_VALUE;
         }
 
-        @Override
-        default Node.OfInt flatten(IntFunction<Integer[]> generator) {
-            return NodeUtils.intFlatten(this);
-        }
     }
 
     /** Specialized {@code Node} for long elements */
@@ -420,10 +412,6 @@
         }
 
 
-        @Override
-        default Node.OfLong flatten(IntFunction<Long[]> generator) {
-            return NodeUtils.longFlatten(this);
-        }
     }
 
     /** Specialized {@code Node} for double elements */
@@ -540,9 +528,5 @@
             return StreamShape.DOUBLE_VALUE;
         }
 
-        @Override
-        default Node.OfDouble flatten(IntFunction<Double[]> generator) {
-            return NodeUtils.doubleFlatten(this);
-        }
     }
 }
--- a/src/share/classes/java/util/stream/ReferencePipeline.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/ReferencePipeline.java	Thu Apr 04 20:18:30 2013 -0400
@@ -380,7 +380,8 @@
         // Runtime checking will be performed when an element is stored in A[], thus if A is not a
         // super type of U an ArrayStoreException will be thrown.
         IntFunction rawGenerator = (IntFunction) generator;
-        return (A[]) evaluateToArrayNode(rawGenerator).asArray(rawGenerator);
+        return (A[]) NodeUtils.flatten(evaluateToArrayNode(rawGenerator), rawGenerator)
+                              .asArray(rawGenerator);
     }
 
     @Override
--- a/src/share/classes/java/util/stream/StreamOpFlag.java	Thu Apr 04 16:18:02 2013 -0700
+++ b/src/share/classes/java/util/stream/StreamOpFlag.java	Thu Apr 04 20:18:30 2013 -0400
@@ -27,7 +27,6 @@
 import java.util.EnumMap;
 import java.util.Map;
 import java.util.Spliterator;
-import java.util.StringJoiner;
 
 /**
  * Flags corresponding to characteristics of streams and operations. Flags are