Repository: kafka Updated Branches: refs/heads/0.9.0 c2b732584 -> 6b8515817
MINOR: Avoid unnecessary `ConcurrentHashMap.get` Also remove incorrect comment. Author: Ismael Juma <[email protected]> Reviewers: Guozhang Wang Closes #790 from ijuma/avoid-unnecessary-get (cherry picked from commit 23b8740d82e4c009fcfb4827f7cd673210bde3b4) Signed-off-by: Guozhang Wang <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/kafka/repo Commit: http://git-wip-us.apache.org/repos/asf/kafka/commit/6b851581 Tree: http://git-wip-us.apache.org/repos/asf/kafka/tree/6b851581 Diff: http://git-wip-us.apache.org/repos/asf/kafka/diff/6b851581 Branch: refs/heads/0.9.0 Commit: 6b85158173275f06a700296ec31535130a9a45c7 Parents: c2b7325 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:28 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/6b851581/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 d4a8a23..9d5c9d9 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 @@ -374,15 +374,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; } /**
