You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by be...@apache.org on 2015/07/02 09:52:26 UTC

cassandra git commit: Enforce simple << complex sort order more strictly and efficiently

Repository: cassandra
Updated Branches:
  refs/heads/trunk 22590c72a -> 6092b01e3


Enforce simple << complex sort order more strictly and efficiently

patch by benedict; reviewed by slebresne for CASSANDRA-9701


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/6092b01e
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/6092b01e
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/6092b01e

Branch: refs/heads/trunk
Commit: 6092b01e329246fc524400aaced63c82d55e017a
Parents: 22590c7
Author: Benedict Elliott Smith <be...@apache.org>
Authored: Thu Jul 2 08:52:03 2015 +0100
Committer: Benedict Elliott Smith <be...@apache.org>
Committed: Thu Jul 2 08:52:03 2015 +0100

----------------------------------------------------------------------
 .../cassandra/config/ColumnDefinition.java      | 24 ++++++++++++--------
 1 file changed, 15 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/6092b01e/src/java/org/apache/cassandra/config/ColumnDefinition.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/ColumnDefinition.java b/src/java/org/apache/cassandra/config/ColumnDefinition.java
index ea00816..d6605a7 100644
--- a/src/java/org/apache/cassandra/config/ColumnDefinition.java
+++ b/src/java/org/apache/cassandra/config/ColumnDefinition.java
@@ -54,6 +54,7 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
         {
             return this == PARTITION_KEY || this == CLUSTERING_COLUMN;
         }
+
     }
 
     public final Kind kind;
@@ -72,6 +73,17 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
     private final Comparator<CellPath> cellPathComparator;
     private final Comparator<Cell> cellComparator;
 
+    /**
+     * These objects are compared frequently, so we encode several of their comparison components
+     * into a single int value so that this can be done efficiently
+     */
+    private final int comparisonOrder;
+
+    private static int comparisonOrder(Kind kind, boolean isComplex, int position)
+    {
+        return (kind.ordinal() << 28) | (isComplex ? 1 << 27 : 0) | position;
+    }
+
     public static ColumnDefinition partitionKeyDef(CFMetaData cfm, ByteBuffer name, AbstractType<?> validator, Integer componentIndex)
     {
         return new ColumnDefinition(cfm, name, validator, componentIndex, Kind.PARTITION_KEY);
@@ -145,6 +157,7 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
         this.setIndexType(indexType, indexOptions);
         this.cellPathComparator = makeCellPathComparator(kind, validator);
         this.cellComparator = makeCellComparator(cellPathComparator);
+        this.comparisonOrder = comparisonOrder(kind, isComplex(), position());
     }
 
     private static Comparator<CellPath> makeCellPathComparator(Kind kind, AbstractType<?> validator)
@@ -399,15 +412,8 @@ public class ColumnDefinition extends ColumnSpecification implements Comparable<
         if (this == other)
             return 0;
 
-        if (kind != other.kind)
-            return kind.ordinal() < other.kind.ordinal() ? -1 : 1;
-        if (position() != other.position())
-            return position() < other.position() ? -1 : 1;
-
-        if (isStatic() != other.isStatic())
-            return isStatic() ? -1 : 1;
-        if (isComplex() != other.isComplex())
-            return isComplex() ? 1 : -1;
+        if (comparisonOrder != other.comparisonOrder)
+            return comparisonOrder - other.comparisonOrder;
 
         return ByteBufferUtil.compareUnsigned(name.bytes, other.name.bytes);
     }