You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2013/08/01 19:06:41 UTC

git commit: improve DecimalSerializer performance

Updated Branches:
  refs/heads/trunk 66f0d6b73 -> dbe53c811


improve DecimalSerializer performance


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

Branch: refs/heads/trunk
Commit: dbe53c811fea105f0a98adbb21850348ce37d336
Parents: 66f0d6b
Author: Jonathan Ellis <jb...@apache.org>
Authored: Thu Aug 1 12:06:18 2013 -0500
Committer: Jonathan Ellis <jb...@apache.org>
Committed: Thu Aug 1 12:06:39 2013 -0500

----------------------------------------------------------------------
 CHANGES.txt                                          |  1 +
 .../cassandra/serializers/DecimalSerializer.java     | 15 ++++++---------
 2 files changed, 7 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/dbe53c81/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index ff3ea41..a0cd6af 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,4 +1,5 @@
 2.0.0-rc1
+ * improve DecimalSerializer performance (CASSANDRA-5837)
  * fix potential spurious wakeup in AsyncOneResponse (CASSANDRA-5690)
  * fix schema-related trigger issues (CASSANDRA-5774)
  * Better validation when accessing CQL3 table from thrift (CASSANDRA-5138)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/dbe53c81/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/serializers/DecimalSerializer.java b/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
index 0ffea9e..819789f 100644
--- a/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
+++ b/src/java/org/apache/cassandra/serializers/DecimalSerializer.java
@@ -48,17 +48,14 @@ public class DecimalSerializer implements TypeSerializer<BigDecimal>
             return ByteBufferUtil.EMPTY_BYTE_BUFFER;
 
         BigInteger bi = value.unscaledValue();
-        Integer scale = value.scale();
+        int scale = value.scale();
         byte[] bibytes = bi.toByteArray();
-        byte[] sbytes = ByteBufferUtil.bytes(scale).array();
-        byte[] bytes = new byte[bi.toByteArray().length + 4];
 
-        for (int i = 0; i < 4; i++)
-            bytes[i] = sbytes[i];
-        for (int i = 4; i < bibytes.length + 4; i++)
-            bytes[i] = bibytes[i - 4];
-
-        return ByteBuffer.wrap(bytes);
+        ByteBuffer bytes = ByteBuffer.allocate(4 + bibytes.length);
+        bytes.putInt(scale);
+        bytes.put(bibytes);
+        bytes.rewind();
+        return bytes;
     }
 
     public void validate(ByteBuffer bytes) throws MarshalException