Optimize for single TransactionSynchronization

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

See gh-27335
This commit is contained in:
Philippe Marschall 2021-08-30 13:06:14 +02:00 committed by Stephane Nicoll
parent e737e6d9ba
commit fd18c00e50
1 changed files with 3 additions and 0 deletions

View File

@ -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);