mirror of https://github.com/apache/kafka.git
MINOR: Optimize map lookup efficiency with getOrDefault (#20229)
Optimized `getRemainingRecords()` method by replacing inefficient `containsKey() + get()` pattern with `getOrDefault()` to reduce map lookups from 2 to 1 per partition. Reviewers: Chia-Ping Tsai <chia7712@gmail.com>
This commit is contained in:
parent
57e9f98e15
commit
c49ab6b4ae
|
@ -216,11 +216,7 @@ public class ExactlyOnceMessageProcessor extends Thread implements ConsumerRebal
|
|||
}
|
||||
return consumer.assignment().stream().mapToLong(partition -> {
|
||||
long currentPosition = consumer.position(partition);
|
||||
if (fullEndOffsets.containsKey(partition)) {
|
||||
return fullEndOffsets.get(partition) - currentPosition;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
return fullEndOffsets.getOrDefault(partition, currentPosition) - currentPosition;
|
||||
}).sum();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue