Skip to content

Commit fed4a7b

Browse files
Eliminate list and flux allocation for sync binds
1 parent 0e3585e commit fed4a7b

File tree

1 file changed

+20
-2
lines changed

1 file changed

+20
-2
lines changed

src/main/java/oracle/r2dbc/impl/OracleStatementImpl.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,6 +952,17 @@ private JdbcStatement(PreparedStatement preparedStatement, Object[] binds) {
952952
* @return A publisher that emits the result of executing this statement
953953
*/
954954
final Publisher<OracleResultImpl> execute() {
955+
956+
if(true)return Flux.usingWhen(Mono.just(new ArrayList<>(1)),
957+
results ->
958+
Mono.from(bind())
959+
.thenMany(executeJdbc())
960+
.map(this::getWarnings)
961+
.doOnNext(results::add)
962+
.onErrorResume(R2dbcException.class, r2dbcException ->
963+
Mono.just(createErrorResult(r2dbcException))),
964+
this::deallocate);
965+
955966
List<OracleResultImpl> results = new ArrayList<>(1);
956967
Publisher<OracleResultImpl> deallocate =
957968
Mono.defer(() -> Mono.from(deallocate(results)))
@@ -989,7 +1000,7 @@ protected Publisher<Void> bind() {
9891000

9901001
protected final Publisher<Void> bind(Object[] binds) {
9911002
return adapter.getLock().flatMap(() -> {
992-
List<Publisher<Void>> bindPublishers = new ArrayList<>(0);
1003+
List<Publisher<Void>> bindPublishers = null;
9931004
for (int i = 0; i < binds.length; i++) {
9941005

9951006
if (binds[i] instanceof Parameter.Out
@@ -1009,13 +1020,20 @@ protected final Publisher<Void> bind(Object[] binds) {
10091020
.doOnSuccess(allocatedValue ->
10101021
setBind(indexFinal, allocatedValue, jdbcType))
10111022
.then();
1023+
1024+
if (bindPublishers == null)
1025+
bindPublishers = new LinkedList<>();
1026+
10121027
bindPublishers.add(bindPublisher);
10131028
}
10141029
else {
10151030
setBind(i, jdbcValue, jdbcType);
10161031
}
10171032
}
1018-
return Flux.concat(bindPublishers);
1033+
1034+
return bindPublishers == null
1035+
? Mono.empty()
1036+
: Flux.concat(bindPublishers);
10191037
});
10201038
}
10211039

0 commit comments

Comments
 (0)