jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject svn commit: r161914 - incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java
Date Tue, 19 Apr 2005 16:24:06 GMT
Author: stefan
Date: Tue Apr 19 09:24:05 2005
New Revision: 161914

URL: http://svn.apache.org/viewcvs?view=rev&rev=161914
Log:
internalize localName and namespaceURI fields of QName to improve performance of equals()
as this is called heavily

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

Modified: incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java
URL: http://svn.apache.org/viewcvs/incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java?view=diff&r1=161913&r2=161914
==============================================================================
--- incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java (original)
+++ incubator/jackrabbit/trunk/src/java/org/apache/jackrabbit/core/QName.java Tue Apr 19 09:24:05
2005
@@ -80,10 +80,10 @@
     /** The memorized string representation of this qualified name. */
     private transient String string;
 
-    /** The namespace URI of this qualified name. */
+    /** The internalized namespace URI of this qualified name. */
     protected final String namespaceURI;
 
-    /** The local part of this qualified name. */
+    /** The internalized local part of this qualified name. */
     protected final String localName;
 
     /**
@@ -101,8 +101,10 @@
         if (localName == null) {
             throw new IllegalArgumentException("invalid localName specified");
         }
-        this.namespaceURI = namespaceURI;
-        this.localName = localName;
+        // internalize both namespaceURI and localName to improve performance
+        // of QName comparisons
+        this.namespaceURI = namespaceURI.intern();
+        this.localName = localName.intern();
         hash = 0;
     }
 
@@ -322,8 +324,10 @@
         }
         if (obj instanceof QName) {
             QName other = (QName) obj;
-            return localName.equals(other.localName)
-                    && namespaceURI.equals(other.namespaceURI);
+            // localName & namespaceURI are internalized,
+            // we only have to compare their references
+            return localName == other.localName
+                    && namespaceURI == other.namespaceURI;
         }
         return false;
     }
@@ -372,5 +376,4 @@
     public int compareTo(Object o) throws ClassCastException {
         return toString().compareTo(((QName) o).toString());
     }
-
 }



Mime
View raw message