Skip to content

Commit 40e3aa9

Browse files
authored
[ISSUE #9553] Improve performance by avoiding repeated get(key) (#9554)
* [ISSUE #9553] Improve performance by avoiding repeated get(key) * Update
1 parent 1f24f09 commit 40e3aa9

1 file changed

Lines changed: 2 additions & 5 deletions

File tree

broker/src/main/java/org/apache/rocketmq/broker/client/ConsumerManager.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.Iterator;
2323
import java.util.List;
2424
import java.util.Map.Entry;
25+
import java.util.Optional;
2526
import java.util.Set;
2627
import java.util.concurrent.ConcurrentHashMap;
2728
import java.util.concurrent.ConcurrentMap;
@@ -386,11 +387,7 @@ public void scanNotActiveChannel() {
386387
}
387388

388389
public HashSet<String> queryTopicConsumeByWho(final String topic) {
389-
HashSet<String> groups = new HashSet<>();
390-
if (this.topicGroupTable.get(topic) != null) {
391-
groups.addAll(this.topicGroupTable.get(topic));
392-
}
393-
return groups;
390+
return new HashSet<>(Optional.ofNullable(topicGroupTable.get(topic)).orElseGet(HashSet::new));
394391
}
395392

396393
public void appendConsumerIdsChangeListener(ConsumerIdsChangeListener listener) {

0 commit comments

Comments
 (0)