Skip to content

Commit 44ae3d0

Browse files
SanneDavideD
authored andcommitted
Remove unneccessary use of IntStream
1 parent e5031ee commit 44ae3d0

File tree

3 files changed

+10
-24
lines changed

3 files changed

+10
-24
lines changed

hibernate-reactive-core/src/main/java/org/hibernate/reactive/loader/ReactiveResultSetProcessor.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.sql.SQLException;
3535
import java.util.List;
3636
import java.util.concurrent.CompletionStage;
37-
import java.util.stream.IntStream;
3837

3938
import static org.hibernate.reactive.util.impl.CompletionStages.completedFuture;
4039

@@ -80,13 +79,16 @@ default CompletionStage<Void> initializeEntity(
8079
);
8180

8281
final Object[] hydratedState = entityEntry.getLoadedState();
83-
return CompletionStages.loopWithoutTrampoline(
84-
IntStream.range( 0, hydratedState.length )
85-
.filter( i-> hydratedState[ i ] instanceof CompletionStage ),
86-
i -> ( (CompletionStage<Object>) hydratedState[ i ] )
87-
.thenAccept( initializedEntity -> hydratedState[ i ] = initializedEntity )
88-
)
89-
.thenAccept(
82+
CompletionStage<Void> loop = CompletionStages.voidFuture();
83+
for ( int i = 0; i < hydratedState.length; i++ ) {
84+
final Object o = hydratedState[i];
85+
if ( o instanceof CompletionStage ) {
86+
final CompletionStage<?> c = (CompletionStage) o;
87+
final int currentIndex = i;
88+
loop = loop.thenCompose( v -> c.thenAccept( initializedEntity -> hydratedState[ currentIndex ] = initializedEntity ) );
89+
}
90+
}
91+
return loop.thenAccept(
9092
v -> TwoPhaseLoad.initializeEntityFromEntityEntryLoadedState(
9193
entity,
9294
entityEntry,

hibernate-reactive-core/src/main/java/org/hibernate/reactive/util/impl/CompletionStages.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -234,13 +234,6 @@ public static CompletionStage<Void> applyToAll(Function<Object, CompletionStage<
234234
}
235235
}
236236

237-
/**
238-
* Same as {@link #loop(Stream, Function)} but doesn't use the trampoline pattern
239-
*/
240-
public static CompletionStage<Void> loopWithoutTrampoline(IntStream stream, Function<Integer,CompletionStage<?>> consumer) {
241-
return loopWithoutTrampoline( stream.iterator(), consumer );
242-
}
243-
244237
/**
245238
* Same as {@link #loop(Iterator, Function)} but doesn't use the trampoline pattern
246239
*/

hibernate-reactive-core/src/test/java/org/hibernate/reactive/CompletionStagesTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,6 @@ public void testLoopOnIntStream(TestContext context) {
111111
);
112112
}
113113

114-
@Test
115-
public void testLoopOnIntStreamWithoutTrampoline(TestContext context) {
116-
test( context, loopWithoutTrampoline(
117-
IntStream.range( 0, entries.length ),
118-
index -> completedFuture( looped.add( entries[index] ) )
119-
).thenAccept( v -> assertThat( looped ).containsExactly( entries ) )
120-
);
121-
}
122-
123114
@Test
124115
public void testLoopWithIteratorWithoutTrampoline(TestContext context) {
125116
test( context, loopWithoutTrampoline(

0 commit comments

Comments
 (0)