Skip to content

Loading…

Serialization optimization for UUID keys. #94

Open
wants to merge 6 commits into from

2 participants

@joval

Hi Jan,

This is a change from a user who follows my clone of JDBM. I think it looks like a good change; you might want to consider merging it yourself.

Here is the diff ignoring whitespace changes:

diff --git a/src/main/java/org/apache/jdbm/Serialization.java b/src/main/java/org/apache/jdbm/Serialization.java
index b8fccce..0e1d56a 100644
--- a/src/main/java/org/apache/jdbm/Serialization.java
+++ b/src/main/java/org/apache/jdbm/Serialization.java
@@ -263,6 +263,10 @@ public class Serialization extends SerialClassInfo implements Serializer {
out.write(DATE);
out.writeLong(((Date) obj).getTime());
return;

  • } else if (clazz == UUID.class) {
  • out.write(UUID);
  • serializeUUID(out,(UUID) obj);
  •        return;
     } else if (clazz == BTree.class) {
         out.write(BTREE);
         ((BTree) obj).writeExternal(out);
    

    @@ -407,6 +411,12 @@ public class Serialization extends SerialClassInfo implements Serializer {

    }

  • private void serializeUUID(DataOutput out, UUID uuid) throws IOException

  • {
  • out.writeLong(uuid.getMostSignificantBits());
  • out.writeLong(uuid.getLeastSignificantBits());
  • }

  • private void serializeMap(int header, DataOutput out, Object obj, FastArrayList objectStack) throws IOException { Map l = (Map) obj; out.write(header); @@ -432,7 +442,6 @@ public class Serialization extends SerialClassInfo implements Serializer { out.write(b); }

 private void writeLongArray(DataOutput da, long[] obj) throws IOException {
     long max = Long.MIN_VALUE;
     long min = Long.MAX_VALUE;

@@ -824,6 +833,9 @@ public class Serialization extends SerialClassInfo implements Serializer {
case DATE:
ret = new Date(is.readLong());
break;

  • case UUID:
  • ret = deserializeUUID(is);
  •           break;
         case ARRAY_INT_B_255:
             ret = deserializeArrayIntB255(is);
             break;
    

    @@ -1068,6 +1080,11 @@ public class Serialization extends SerialClassInfo implements Serializer {
    return ret;
    }

  • private UUID deserializeUUID(DataInput is) throws IOException

  • {
  • return new UUID(is.readLong(), is.readLong());
  • }
    +
    private int[] deserializeArrayIntB255(DataInput is) throws IOException {
    int size = is.readUnsignedByte();
    if (size < 0)
    diff --git a/src/main/java/org/apache/jdbm/SerializationHeader.java b/src/main/java/org/apache/jdbm/SerializationHeader.java
    index e3ec45c..8e86836 100644
    --- a/src/main/java/org/apache/jdbm/SerializationHeader.java
    +++ b/src/main/java/org/apache/jdbm/SerializationHeader.java
    @@ -120,6 +120,7 @@ final class SerializationHeader {

    final static int CLASS = 126;
    final static int DATE = 127;

  • final static int UUID = 128;

    static final int JDBMLINKEDLIST = 159;
    diff --git a/src/test/java/org/apache/jdbm/SerializationTest.java b/src/test/java/org/apache/jdbm/SerializationTest.java
    index c61f743..57a58e7 100644
    --- a/src/test/java/org/apache/jdbm/SerializationTest.java
    +++ b/src/test/java/org/apache/jdbm/SerializationTest.java
    @@ -399,6 +399,18 @@ public class SerializationTest extends TestCase {
    assertEquals(d, ser.deserialize(ser.serialize(d)));
    }

  • public void testUUID() throws IOException, ClassNotFoundException {

  • //try a bunch of UUIDs.
  • for(int i = 0; i < 1000;i++)
  • {
  • UUID uuid = UUID.randomUUID();
  • SimpleEntry a = new SimpleEntry(uuid, "11");
  • byte[] buf = ser.serialize(a);
  • SimpleEntry b = (SimpleEntry) ser.deserialize(buf);
  • assertEquals(b, a);
  • }
  • }
    +

    public void testLocale() throws Exception{
    assertEquals(Locale.FRANCE, ser.deserialize(ser.serialize(Locale.FRANCE)));

David A. Solin and others added some commits
David A. Solin Fixed some NullPointerExceptions exhibited in usage. aa1e455
David A. Solin Merge remote-tracking branch 'upstream/master'
Conflicts:
	src/main/java/org/apache/jdbm/DBAbstract.java
cd825e2
@zig158 zig158 Added Optimized Serialization for UUID 2a4fc6b
jOVAL.org Merge pull request #1 from zig158/master
Added Optimized Serialization for UUID
799199c
David A. Solin Merge remote-tracking branch 'upstream/master'
Conflicts:
	src/main/java/org/apache/jdbm/Serialization.java
b8ddecd
David A. Solin Merge fix. 4300bd1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 26, 2012
  1. Fixed some NullPointerExceptions exhibited in usage.

    David A. Solin committed
Commits on Aug 23, 2012
  1. Merge remote-tracking branch 'upstream/master'

    David A. Solin committed
    Conflicts:
    	src/main/java/org/apache/jdbm/DBAbstract.java
Commits on Sep 3, 2012
  1. @zig158
Commits on Sep 4, 2012
  1. Merge pull request #1 from zig158/master

    jOVAL.org committed
    Added Optimized Serialization for UUID
Commits on Mar 30, 2013
  1. Merge remote-tracking branch 'upstream/master'

    David A. Solin committed
    Conflicts:
    	src/main/java/org/apache/jdbm/Serialization.java
  2. Merge fix.

    David A. Solin committed
Something went wrong with that request. Please try again.