jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mreut...@apache.org
Subject svn commit: r292691 - in /incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name: Path.java QName.java
Date Fri, 30 Sep 2005 10:09:27 GMT
Author: mreutegg
Date: Fri Sep 30 03:09:23 2005
New Revision: 292691

URL: http://svn.apache.org/viewcvs?rev=292691&view=rev
Log:
Some performance improvements
- Reuse Matcher instance in a threadlocal
- avoid string creation in QName.compareTo()

Modified:
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/Path.java
    incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/QName.java

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/Path.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/Path.java?rev=292691&r1=292690&r2=292691&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/Path.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/Path.java Fri Sep 30 03:09:23
2005
@@ -128,6 +128,15 @@
             + "(\\[([1-9]\\d*)\\])?");
 
     /**
+     * Matcher instance as thread-local.
+     */
+    private static final ThreadLocal PATH_ELEMENT_MATCHER = new ThreadLocal() {
+        protected Object initialValue() {
+            return PATH_ELEMENT_PATTERN.matcher("dummy");
+        }
+    };
+
+    /**
      * the elements of this path
      */
     private final PathElement[] elements;
@@ -375,7 +384,8 @@
                 // ignore trailing '/'
                 break;
             }
-            Matcher matcher = PATH_ELEMENT_PATTERN.matcher(elem);
+            Matcher matcher = (Matcher) PATH_ELEMENT_MATCHER.get();
+            matcher.reset(elem);
             if (matcher.matches()) {
                 if (resolver == null) {
                     // check only

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/QName.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/QName.java?rev=292691&r1=292690&r2=292691&view=diff
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/QName.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/name/QName.java Fri Sep 30 03:09:23
2005
@@ -90,6 +90,15 @@
             "(([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?):)?"
             + "([^ /:\\[\\]*'\"|](?:[^/:\\[\\]*'\"|]*[^ /:\\[\\]*'\"|])?)");
 
+    /**
+     * Matcher instance as thread-local.
+     */
+    private static final ThreadLocal NAME_MATCHER = new ThreadLocal() {
+        protected Object initialValue() {
+            return NAME_PATTERN.matcher("dummy");
+        }
+    };
+
     /** The memorized hash code of this qualified name. */
     private transient int hash;
 
@@ -235,7 +244,9 @@
         String prefix;
         String localName;
 
-        Matcher matcher = NAME_PATTERN.matcher(jcrName);
+
+        Matcher matcher = (Matcher) NAME_MATCHER.get();
+        matcher.reset(jcrName);
         if (matcher.matches()) {
             // check for prefix (group 1)
             if (matcher.group(1) != null) {
@@ -412,6 +423,8 @@
      * @see Comparable#compareTo(Object)
      */
     public int compareTo(Object o) throws ClassCastException {
-        return toString().compareTo(((QName) o).toString());
+        QName other = (QName) o;
+        int result = namespaceURI.compareTo(other.namespaceURI);
+        return (result != 0) ? result : localName.compareTo(other.localName);
     }
 }



Mime
View raw message