In RowDataResolver, reduce calls to replies.size(), and use replies.peek() instead of replies.iterator().next()
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f099e086 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f099e086 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f099e086 Branch: refs/heads/cassandra-2.1.0 Commit: f099e086f3f002789e24bd6c58e52b7553cd5381 Parents: 852f084 Author: Benedict Elliott Smith <bened...@apache.org> Authored: Tue Sep 9 09:36:14 2014 +0700 Committer: Benedict Elliott Smith <bened...@apache.org> Committed: Tue Sep 9 09:38:16 2014 +0700 ---------------------------------------------------------------------- .../apache/cassandra/service/AbstractRowResolver.java | 4 ++-- .../org/apache/cassandra/service/RowDataResolver.java | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/f099e086/src/java/org/apache/cassandra/service/AbstractRowResolver.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/AbstractRowResolver.java b/src/java/org/apache/cassandra/service/AbstractRowResolver.java index 1fbb92b..fbbf473 100644 --- a/src/java/org/apache/cassandra/service/AbstractRowResolver.java +++ b/src/java/org/apache/cassandra/service/AbstractRowResolver.java @@ -18,7 +18,7 @@ package org.apache.cassandra.service; import java.nio.ByteBuffer; -import java.util.Collection; +import java.util.Queue; import java.util.concurrent.ConcurrentLinkedQueue; import org.slf4j.Logger; @@ -35,7 +35,7 @@ public abstract class AbstractRowResolver implements IResponseResolver<ReadRespo protected final String keyspaceName; // CLQ gives us thread-safety without the overhead of guaranteeing uniqueness like a Set would - protected final Collection<MessageIn<ReadResponse>> replies = new ConcurrentLinkedQueue<>(); + protected final Queue<MessageIn<ReadResponse>> replies = new ConcurrentLinkedQueue<>(); protected final DecoratedKey key; public AbstractRowResolver(ByteBuffer key, String keyspaceName) http://git-wip-us.apache.org/repos/asf/cassandra/blob/f099e086/src/java/org/apache/cassandra/service/RowDataResolver.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/service/RowDataResolver.java b/src/java/org/apache/cassandra/service/RowDataResolver.java index f5eee40..9c24776 100644 --- a/src/java/org/apache/cassandra/service/RowDataResolver.java +++ b/src/java/org/apache/cassandra/service/RowDataResolver.java @@ -57,15 +57,16 @@ public class RowDataResolver extends AbstractRowResolver */ public Row resolve() throws DigestMismatchException { + int replyCount = replies.size(); if (logger.isDebugEnabled()) - logger.debug("resolving {} responses", replies.size()); + logger.debug("resolving {} responses", replyCount); long start = System.nanoTime(); ColumnFamily resolved; - if (replies.size() > 1) + if (replyCount > 1) { - List<ColumnFamily> versions = new ArrayList<ColumnFamily>(replies.size()); - List<InetAddress> endpoints = new ArrayList<InetAddress>(replies.size()); + List<ColumnFamily> versions = new ArrayList<>(replyCount); + List<InetAddress> endpoints = new ArrayList<>(replyCount); for (MessageIn<ReadResponse> message : replies) { @@ -158,7 +159,7 @@ public class RowDataResolver extends AbstractRowResolver public Row getData() { - return replies.iterator().next().payload.row(); + return replies.peek().payload.row(); } public boolean isDataPresent()