This is an automated email from the ASF dual-hosted git repository. yong pushed a commit to branch branch-4.15 in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
commit e2e1115661509e650d4a5c789a958e2e0cd617e4 Author: 萧易客 <[email protected]> AuthorDate: Sat Oct 8 10:24:28 2022 +0800 Reduce unnecessary loop in removeIf if section is empty (#3512) Reduce unnecessary loop in removeIf if section is empty (cherry picked from commit bc87bfbea5816b382a7fe54639d71b404736ba62) --- .../org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java | 2 +- .../apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java | 4 ++-- .../org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java index dd2b6c1bc8..be11a4ebc3 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongHashMap.java @@ -533,7 +533,7 @@ public class ConcurrentLongHashMap<V> { try { // Go through all the buckets for this section int capacity = this.capacity; - for (int bucket = 0; bucket < capacity; bucket++) { + for (int bucket = 0; size > 0 && bucket < capacity; bucket++) { long storedKey = keys[bucket]; V storedValue = values[bucket]; diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java index 99a3dde772..f54a9645ac 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentLongLongHashMap.java @@ -682,7 +682,7 @@ public class ConcurrentLongLongHashMap { int removedCount = 0; try { // Go through all the buckets for this section - for (int bucket = 0; bucket < table.length; bucket += 2) { + for (int bucket = 0; size > 0 && bucket < table.length; bucket += 2) { long storedKey = table[bucket]; if (storedKey != DeletedKey && storedKey != EmptyKey) { @@ -720,7 +720,7 @@ public class ConcurrentLongLongHashMap { int removedCount = 0; try { // Go through all the buckets for this section - for (int bucket = 0; bucket < table.length; bucket += 2) { + for (int bucket = 0; size > 0 && bucket < table.length; bucket += 2) { long storedKey = table[bucket]; long storedValue = table[bucket + 1]; diff --git a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java index 2690e69766..b4de6544ce 100644 --- a/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java +++ b/bookkeeper-server/src/main/java/org/apache/bookkeeper/util/collections/ConcurrentOpenHashMap.java @@ -528,7 +528,7 @@ public class ConcurrentOpenHashMap<K, V> { int removedCount = 0; try { // Go through all the buckets for this section - for (int bucket = 0; bucket < table.length; bucket += 2) { + for (int bucket = 0; size > 0 && bucket < table.length; bucket += 2) { K storedKey = (K) table[bucket]; V storedValue = (V) table[bucket + 1];
