jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1566669 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java
Date Mon, 10 Feb 2014 16:02:13 GMT
Author: jukka
Date: Mon Feb 10 16:02:13 2014
New Revision: 1566669

URL: http://svn.apache.org/r1566669
Log:
JCR-3721: Slow and actively called NodeId.toString()

Drop table lookups to squeeze out a few more nanoseconds out of NodeId.toString()

Modified:
    jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java

Modified: jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java
URL: http://svn.apache.org/viewvc/jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java?rev=1566669&r1=1566668&r2=1566669&view=diff
==============================================================================
--- jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java
(original)
+++ jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java
Mon Feb 10 16:02:13 2014
@@ -243,21 +243,6 @@ public class NodeId implements ItemId, C
 
     //--------------------------------------------------------------< Object >
 
-    final static String[] digits = new String[256];
-    static {
-      for ( int i=0; i<digits.length; ++i ) {
-        digits[i] = String.format("%02x", i);
-      }
-    }
-
-    final static int[] indexes = {
-      0, 1, 2, 3, 4, 5, 6, 7,
-      9, 10, 11, 12,
-      14, 15, 16, 17,
-      19, 20, 21, 22,
-      24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35
-    };
-
     /**
      * Returns the UUID string representation of this identifier.
      *
@@ -265,21 +250,33 @@ public class NodeId implements ItemId, C
      * @return UUID string
      */
     public String toString() {
-        //return new UUID(msb, lsb).toString();
-        final char[] retval = new char[36];
-        retval[8] = retval[13] = retval[18] = retval[23] = '-';
-        final byte[] data = getRawBytes();
-        for ( int i=0; i<16; ++i ) {
-          int pos = data[i];
-          if ( pos < 0 )
-            pos += 256;
-          final String v = digits[pos];
-          retval[indexes[i*2]] = v.charAt(0);
-          retval[indexes[i*2 + 1]] = v.charAt(1);
-        }
+        char[] retval = new char[36];
+        hex4(retval, 0, msb >>> 48);
+        hex4(retval, 4, msb >>> 32);
+        retval[8]  = '-';
+        hex4(retval, 9, msb >>> 16);
+        retval[13] = '-';
+        hex4(retval, 14, msb);
+        retval[18] = '-';
+        hex4(retval, 19, lsb >>> 48);
+        retval[23] = '-';
+        hex4(retval, 24, lsb >>> 32);
+        hex4(retval, 28, lsb >>> 16);
+        hex4(retval, 32, lsb);
         return new String(retval);
     }
 
+    private static final void hex4(char[] c, int index, long value) {
+        for (int i = 0; i < 4; i++) {
+            long v = (value >>> (12 - i * 4)) & 0xf;
+            if (v < 10) {
+                c[index + i] = (char) (v + '0');
+            } else {
+                c[index + i] = (char) (v - 10 + 'a');
+            }
+        }
+    }
+
     /**
      * Compares two UUID for equality.
      *



Mime
View raw message