cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [1/4] git commit: special-case single-CF mutations to deserialize to singletonMap instead of HashMap
Date Thu, 28 Feb 2013 16:12:20 GMT
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 <jbellis@apache.org>
Authored: Thu Feb 28 09:37:49 2013 -0600
Committer: Jonathan Ellis <jbellis@apache.org>
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<UUID, ColumnFamily> modifications = new HashMap<UUID, ColumnFamily>();
             int size = dis.readInt();
-            for (int i = 0; i < size; ++i)
+
+            Map<UUID, ColumnFamily> 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<UUID, ColumnFamily>();
+                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);


Mime
View raw message