Browse Source

Optimize for single TransactionSynchronization

Optimize TransactionSynchronizationManager.getSynchronizations() to
avoid sorting and ArrayList creation in case of a single
TransactionSynchronization.

See gh-27335
pull/31115/head
Philippe Marschall 3 years ago committed by Stephane Nicoll
parent
commit
fd18c00e50
  1. 3
      spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

3
spring-tx/src/main/java/org/springframework/transaction/support/TransactionSynchronizationManager.java

@ -297,6 +297,9 @@ public abstract class TransactionSynchronizationManager { @@ -297,6 +297,9 @@ public abstract class TransactionSynchronizationManager {
if (synchs.isEmpty()) {
return Collections.emptyList();
}
else if (synchs.size() == 1) {
return Collections.singletonList(synchs.iterator().next());
}
else {
// Sort lazily here, not in registerSynchronization.
List<TransactionSynchronization> sortedSynchs = new ArrayList<>(synchs);

Loading…
Cancel
Save