Return-Path: X-Original-To: apmail-cassandra-commits-archive@www.apache.org Delivered-To: apmail-cassandra-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 26CFDEC84 for ; Thu, 28 Feb 2013 16:12:21 +0000 (UTC) Received: (qmail 2589 invoked by uid 500); 28 Feb 2013 16:12:20 -0000 Delivered-To: apmail-cassandra-commits-archive@cassandra.apache.org Received: (qmail 2531 invoked by uid 500); 28 Feb 2013 16:12:20 -0000 Mailing-List: contact commits-help@cassandra.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cassandra.apache.org Delivered-To: mailing list commits@cassandra.apache.org Received: (qmail 2374 invoked by uid 99); 28 Feb 2013 16:12:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Feb 2013 16:12:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 34E2510F0D; Thu, 28 Feb 2013 16:12:20 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jbellis@apache.org To: commits@cassandra.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [1/4] git commit: special-case single-CF mutations to deserialize to singletonMap instead of HashMap Message-Id: <20130228161220.34E2510F0D@tyr.zones.apache.org> Date: Thu, 28 Feb 2013 16:12:20 +0000 (UTC) special-case single-CF mutations to deserialize to singletonMap instead of HashMap Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/273309ba Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/273309ba Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/273309ba Branch: refs/heads/trunk Commit: 273309babc66f563d01965d7f9185fd94873713b Parents: 7725408 Author: Jonathan Ellis Authored: Thu Feb 28 09:37:49 2013 -0600 Committer: Jonathan Ellis Committed: Thu Feb 28 09:37:49 2013 -0600 ---------------------------------------------------------------------- src/java/org/apache/cassandra/db/RowMutation.java | 35 ++++++++++++---- 1 files changed, 26 insertions(+), 9 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/273309ba/src/java/org/apache/cassandra/db/RowMutation.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/RowMutation.java b/src/java/org/apache/cassandra/db/RowMutation.java index 2b6273c..da67e8d 100644 --- a/src/java/org/apache/cassandra/db/RowMutation.java +++ b/src/java/org/apache/cassandra/db/RowMutation.java @@ -278,21 +278,38 @@ public class RowMutation implements IMutation { String table = dis.readUTF(); ByteBuffer key = ByteBufferUtil.readWithShortLength(dis); - Map modifications = new HashMap(); int size = dis.readInt(); - for (int i = 0; i < size; ++i) + + Map modifications; + if (size == 1) { - // We used to uselessly write the cf id here - if (version < MessagingService.VERSION_12) - ColumnFamily.serializer.deserializeCfId(dis, version); - ColumnFamily cf = ColumnFamily.serializer.deserialize(dis, flag, TreeMapBackedSortedColumns.factory(), version); - // We don't allow RowMutation with null column family, so we should never get null back. - assert cf != null; - modifications.put(cf.id(), cf); + ColumnFamily cf = deserializeOneCf(dis, version, flag); + modifications = Collections.singletonMap(cf.id(), cf); + } + else + { + modifications = new HashMap(); + for (int i = 0; i < size; ++i) + { + ColumnFamily cf = deserializeOneCf(dis, version, flag); + modifications.put(cf.id(), cf); + } } + return new RowMutation(table, key, modifications); } + private ColumnFamily deserializeOneCf(DataInput dis, int version, ColumnSerializer.Flag flag) throws IOException + { + // We used to uselessly write the cf id here + if (version < MessagingService.VERSION_12) + ColumnFamily.serializer.deserializeCfId(dis, version); + ColumnFamily cf = ColumnFamily.serializer.deserialize(dis, flag, TreeMapBackedSortedColumns.factory(), version); + // We don't allow RowMutation with null column family, so we should never get null back. + assert cf != null; + return cf; + } + public RowMutation deserialize(DataInput dis, int version) throws IOException { return deserialize(dis, version, ColumnSerializer.Flag.FROM_REMOTE);