8318421: AbstractPipeline.sourceStageSpliterator() chases pointers needlessly

Reviewed-by: psandoz
This commit is contained in:
Viktor Klang 2023-10-20 16:32:11 +00:00 committed by Paul Sandoz
parent 200b5a27d4
commit 21215753c0

View File

@ -262,8 +262,9 @@ abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
* @throws IllegalStateException if this pipeline stage is not the source * @throws IllegalStateException if this pipeline stage is not the source
* stage. * stage.
*/ */
@SuppressWarnings("unchecked")
final Spliterator<E_OUT> sourceStageSpliterator() { final Spliterator<E_OUT> sourceStageSpliterator() {
// Ensures that this method is only ever called on the sourceStage
if (this != sourceStage) if (this != sourceStage)
throw new IllegalStateException(); throw new IllegalStateException();
@ -271,16 +272,16 @@ abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
throw new IllegalStateException(MSG_STREAM_LINKED); throw new IllegalStateException(MSG_STREAM_LINKED);
linkedOrConsumed = true; linkedOrConsumed = true;
if (sourceStage.sourceSpliterator != null) { if (sourceSpliterator != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Spliterator<E_OUT> s = sourceStage.sourceSpliterator; Spliterator<E_OUT> s = (Spliterator<E_OUT>)sourceSpliterator;
sourceStage.sourceSpliterator = null; sourceSpliterator = null;
return s; return s;
} }
else if (sourceStage.sourceSupplier != null) { else if (sourceSupplier != null) {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
Spliterator<E_OUT> s = (Spliterator<E_OUT>) sourceStage.sourceSupplier.get(); Spliterator<E_OUT> s = (Spliterator<E_OUT>)sourceSupplier.get();
sourceStage.sourceSupplier = null; sourceSupplier = null;
return s; return s;
} }
else { else {
@ -309,8 +310,8 @@ abstract class AbstractPipeline<E_IN, E_OUT, S extends BaseStream<E_OUT, S>>
linkedOrConsumed = true; linkedOrConsumed = true;
sourceSupplier = null; sourceSupplier = null;
sourceSpliterator = null; sourceSpliterator = null;
if (sourceStage.sourceCloseAction != null) { Runnable closeAction = sourceStage.sourceCloseAction;
Runnable closeAction = sourceStage.sourceCloseAction; if (closeAction != null) {
sourceStage.sourceCloseAction = null; sourceStage.sourceCloseAction = null;
closeAction.run(); closeAction.run();
} }