Avoid resizing of fixed-size HashSet/LinkedHashSet variants
Add helpers to CollectionUtils for building HashSets and LinkedHashSets that can hold an expected number of elements without needing to resize/rehash. Closes gh-32291
This commit is contained in:
committed by
Sam Brannen
parent
6383a0d7ca
commit
e1a32d4ba9
@@ -86,7 +86,7 @@ public class DestinationPatternsMessageCondition
|
||||
|
||||
private static Set<String> prependLeadingSlash(String[] patterns, RouteMatcher routeMatcher) {
|
||||
boolean slashSeparator = routeMatcher.combine("a", "a").equals("a/a");
|
||||
Set<String> result = new LinkedHashSet<>(patterns.length);
|
||||
Set<String> result = CollectionUtils.newLinkedHashSet(patterns.length);
|
||||
for (String pattern : patterns) {
|
||||
if (slashSeparator && StringUtils.hasLength(pattern) && !pattern.startsWith("/")) {
|
||||
pattern = "/" + pattern;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.messaging.simp.SimpLogging;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
@@ -216,7 +217,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
|
||||
}
|
||||
else {
|
||||
Set<SimpSession> sessions = user.getSessions();
|
||||
sessionIds = new HashSet<>(sessions.size());
|
||||
sessionIds = CollectionUtils.newHashSet(sessions.size());
|
||||
for (SimpSession session : sessions) {
|
||||
sessionIds.add(session.getId());
|
||||
}
|
||||
|
||||
@@ -414,7 +414,7 @@ public class MultiServerUserRegistry implements SimpUserRegistry, SmartApplicati
|
||||
this.id = session.getId();
|
||||
this.user = new TransferSimpUser();
|
||||
Set<SimpSubscription> subscriptions = session.getSubscriptions();
|
||||
this.subscriptions = new HashSet<>(subscriptions.size());
|
||||
this.subscriptions = CollectionUtils.newHashSet(subscriptions.size());
|
||||
for (SimpSubscription subscription : subscriptions) {
|
||||
this.subscriptions.add(new TransferSimpSubscription(subscription));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user