This is an automated email from the ASF dual-hosted git repository.
lushiji pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/bookkeeper.git
The following commit(s) were added to refs/heads/master by this push:
new bc87bfbea5 Reduce unnecessary loop in removeIf if section is empty
(#3512)
bc87bfbea5 is described below
commit bc87bfbea5816b382a7fe54639d71b404736ba62
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
---
.../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 968dcdb6b3..7ff465f079 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
@@ -531,7 +531,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 095c80ddba..25bcb4061a 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
@@ -681,7 +681,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) {
@@ -719,7 +719,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 57b555ca57..cab3ce8ea3 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
@@ -526,7 +526,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];