You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jackrabbit.apache.org by th...@apache.org on 2009/11/26 15:59:51 UTC

svn commit: r884574 - /jackrabbit/trunk/jackrabbit-core/src/main/java/org/apache/jackrabbit/core/id/NodeId.java

Author: thomasm
Date: Thu Nov 26 14:59:51 2009
New Revision: 884574

URL: http://svn.apache.org/viewvc?rev=884574&view=rev
Log:
JCR-2327 java.util.UUID.fromString() too slow

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=884574&r1=884573&r2=884574&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 Thu Nov 26 14:59:51 2009
@@ -122,8 +122,41 @@
      * @param uuid UUID string
      * @throws IllegalArgumentException if the UUID string is invalid
      */
-    public NodeId(String uuid) throws IllegalArgumentException {
-        this(fromString(uuid));
+    public NodeId(String uuidString) throws IllegalArgumentException {
+        // e.g. f81d4fae-7dec-11d0-a765-00a0c91e6bf6
+        //      012345678901234567890123456789012345
+        if (uuidString.length() != UUID_FORMATTED_LENGTH) {
+            throw new IllegalArgumentException(uuidString);
+        }
+        long m = 0, x = 0;
+        for (int i = 0; i < UUID_FORMATTED_LENGTH; i++) {
+            int c = uuidString.charAt(i);
+            switch (i) {
+            case 18:
+                m = x;
+                x = 0;
+                // fall through
+            case 8:
+            case 13:
+            case 23:
+                if (c != '-') {
+                    throw new IllegalArgumentException(uuidString);
+                }
+                break;
+            default:
+                if (c >= '0' && c <= '9') {
+                    x = (x << 4) | (c - '0');
+                } else if (c >= 'a' && c <= 'f') {
+                    x = (x << 4) | (c - 'a' + 0xa);
+                } else if (c >= 'A' && c <= 'F') {
+                    x = (x << 4) | (c - 'A' + 0xa);
+                } else {
+                    throw new IllegalArgumentException(uuidString);
+                }
+            }
+        }
+        this.msb = m;
+        this.lsb = x;
     }
 
     /**
@@ -246,47 +279,4 @@
         return (int) ((msb >>> 32) ^ msb ^ (lsb >>> 32) ^ lsb);
     }
 
-    //------------------------------------------------------------< internal >
-
-    /**
-     * Constructs a UUID from a UUID formatted String.
-     *
-     * @param uuidString the String representing a UUID to construct this UUID
-     * @return the UUID created from the given string.
-     * @throws IllegalArgumentException String must be a properly formatted UUID
-     *                                  string
-     */
-    private static UUID fromString(String uuidString)
-            throws IllegalArgumentException {
-        // e.g. f81d4fae-7dec-11d0-a765-00a0c91e6bf6
-        //      012345678901234567890123456789012345
-        int len = uuidString.length();
-        if (len != UUID_FORMATTED_LENGTH) {
-            throw new IllegalArgumentException();
-        }
-        long[] words = new long[2];
-        int b = 0;
-        for (int i = 0; i < UUID_FORMATTED_LENGTH; i++) {
-            int c = uuidString.charAt(i) | 0x20; // to lowercase (will lose some error checking)
-            if (i == 8 || i == 13 || i == 23) {
-                if (c != '-') {
-                    throw new IllegalArgumentException(String.valueOf(i));
-                }
-            } else if (i == 18) {
-                if (c != '-') {
-                    throw new IllegalArgumentException(String.valueOf(i));
-                }
-                b = 1;
-            } else {
-                byte h = (byte) (c & 0x0f);
-                if (c >= 'a' && c <= 'f') {
-                    h += 9;
-                } else if (c < '0' || c > '9') {
-                    throw new IllegalArgumentException();
-                }
-                words[b] = words[b] << 4 | h;
-            }
-        }
-        return new UUID(words[0], words[1]);
-    }
 }