src/java.base/share/classes/java/util/stream/Streams.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File 8076112 Sdiff src/java.base/share/classes/java/util/stream

src/java.base/share/classes/java/util/stream/Streams.java

Print this page
rev 12262 : 8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
Summary: Annotate possibly intrinsified methods with @HotSpotIntrinsicCandidate. Add checks omitted by intrinsics to the library code. Add CheckIntrinsics flags to check consistency of intrinsics.
Reviewed-by: jrose, kvn, thartmann, vlivanov, abuckley, darcy, ascarpino, briangoetz, alanb, aph, dnsimon


  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.stream;
  26 
  27 import java.util.Comparator;
  28 import java.util.Objects;
  29 import java.util.Spliterator;
  30 import java.util.function.Consumer;
  31 import java.util.function.DoubleConsumer;
  32 import java.util.function.IntConsumer;
  33 import java.util.function.LongConsumer;

  34 
  35 /**
  36  * Utility methods for operating on and creating streams.
  37  *
  38  * <p>Unless otherwise stated, streams are created as sequential streams.  A
  39  * sequential stream can be transformed into a parallel stream by calling the
  40  * {@code parallel()} method on the created stream.
  41  *
  42  * @since 1.8
  43  */
  44 final class Streams {
  45 
  46     private Streams() {
  47         throw new Error("no instances");
  48     }
  49 
  50     /**
  51      * An object instance representing no value, that cannot be an actual
  52      * data element of a stream.  Used when processing streams that can contain
  53      * {@code null} elements to distinguish between a {@code null} value and no


  81 
  82         @Override
  83         public boolean tryAdvance(IntConsumer consumer) {
  84             Objects.requireNonNull(consumer);
  85 
  86             final int i = from;
  87             if (i < upTo) {
  88                 from++;
  89                 consumer.accept(i);
  90                 return true;
  91             }
  92             else if (last > 0) {
  93                 last = 0;
  94                 consumer.accept(i);
  95                 return true;
  96             }
  97             return false;
  98         }
  99 
 100         @Override

 101         public void forEachRemaining(IntConsumer consumer) {
 102             Objects.requireNonNull(consumer);
 103 
 104             int i = from;
 105             final int hUpTo = upTo;
 106             int hLast = last;
 107             from = upTo;
 108             last = 0;
 109             while (i < hUpTo) {
 110                 consumer.accept(i++);
 111             }
 112             if (hLast > 0) {
 113                 // Last element of closed range
 114                 consumer.accept(i);
 115             }
 116         }
 117 
 118         @Override
 119         public long estimateSize() {
 120             // Ensure ranges of size > Integer.MAX_VALUE report the correct size




  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.util.stream;
  26 
  27 import java.util.Comparator;
  28 import java.util.Objects;
  29 import java.util.Spliterator;
  30 import java.util.function.Consumer;
  31 import java.util.function.DoubleConsumer;
  32 import java.util.function.IntConsumer;
  33 import java.util.function.LongConsumer;
  34 import jdk.internal.HotSpotIntrinsicCandidate;
  35 
  36 /**
  37  * Utility methods for operating on and creating streams.
  38  *
  39  * <p>Unless otherwise stated, streams are created as sequential streams.  A
  40  * sequential stream can be transformed into a parallel stream by calling the
  41  * {@code parallel()} method on the created stream.
  42  *
  43  * @since 1.8
  44  */
  45 final class Streams {
  46 
  47     private Streams() {
  48         throw new Error("no instances");
  49     }
  50 
  51     /**
  52      * An object instance representing no value, that cannot be an actual
  53      * data element of a stream.  Used when processing streams that can contain
  54      * {@code null} elements to distinguish between a {@code null} value and no


  82 
  83         @Override
  84         public boolean tryAdvance(IntConsumer consumer) {
  85             Objects.requireNonNull(consumer);
  86 
  87             final int i = from;
  88             if (i < upTo) {
  89                 from++;
  90                 consumer.accept(i);
  91                 return true;
  92             }
  93             else if (last > 0) {
  94                 last = 0;
  95                 consumer.accept(i);
  96                 return true;
  97             }
  98             return false;
  99         }
 100 
 101         @Override
 102         @HotSpotIntrinsicCandidate
 103         public void forEachRemaining(IntConsumer consumer) {
 104             Objects.requireNonNull(consumer);
 105 
 106             int i = from;
 107             final int hUpTo = upTo;
 108             int hLast = last;
 109             from = upTo;
 110             last = 0;
 111             while (i < hUpTo) {
 112                 consumer.accept(i++);
 113             }
 114             if (hLast > 0) {
 115                 // Last element of closed range
 116                 consumer.accept(i);
 117             }
 118         }
 119 
 120         @Override
 121         public long estimateSize() {
 122             // Ensure ranges of size > Integer.MAX_VALUE report the correct size


src/java.base/share/classes/java/util/stream/Streams.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File