Repository: kafka Updated Branches: refs/heads/trunk a1efe6332 -> 23b8740d8
MINOR: Avoid unnecessary `ConcurrentHashMap.get` Also remove incorrect comment. Author: Ismael Juma <[email protected]> Reviewers: Guozhang Wang Closes #790 from ijuma/avoid-unnecessary-get Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/23b8740d Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/23b8740d Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/23b8740d Branch: refs/heads/trunk Commit: 23b8740d82e4c009fcfb4827f7cd673210bde3b4 Parents: a1efe63 Author: Ismael Juma <[email protected]> Authored: Tue Jan 19 09:22:13 2016 -0800 Committer: Guozhang Wang <[email protected]> Committed: Tue Jan 19 09:22:13 2016 -0800 ---------------------------------------------------------------------- .../clients/producer/internals/RecordAccumulator.java | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/kafka/blob/23b8740d/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java ---------------------------------------------------------------------- diff --git a/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java b/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java index 4b394f9..d36234c 100644 --- a/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java +++ b/clients/src/main/java/org/apache/kafka/clients/producer/internals/RecordAccumulator.java @@ -372,15 +372,18 @@ public final class RecordAccumulator { } /** - * Get the deque for the given topic-partition, creating it if necessary. Since new topics will only be added rarely - * we copy-on-write the hashmap + * Get the deque for the given topic-partition, creating it if necessary. */ private Deque<RecordBatch> dequeFor(TopicPartition tp) { Deque<RecordBatch> d = this.batches.get(tp); if (d != null) return d; - this.batches.putIfAbsent(tp, new ArrayDeque<RecordBatch>()); - return this.batches.get(tp); + d = new ArrayDeque<>(); + Deque<RecordBatch> previous = this.batches.putIfAbsent(tp, d); + if (previous == null) + return d; + else + return previous; } /**
