jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1448927 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: PropertyTemplate.java Template.java
Date Fri, 22 Feb 2013 08:11:44 GMT
Author: jukka
Date: Fri Feb 22 08:11:44 2013
New Revision: 1448927

URL: http://svn.apache.org/r1448927
Log:
OAK-593: Segment-based MK

Order property templates by hash code for faster lookup

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java?rev=1448927&r1=1448926&r2=1448927&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/PropertyTemplate.java
Fri Feb 22 08:11:44 2013
@@ -54,6 +54,7 @@ class PropertyTemplate implements Compar
     public int compareTo(PropertyTemplate template) {
         checkNotNull(template);
         return ComparisonChain.start()
+                .compare(hashCode(), template.hashCode()) // important
                 .compare(name, template.name)
                 .compare(type, template.type)
                 .result();
@@ -75,7 +76,7 @@ class PropertyTemplate implements Compar
 
     @Override
     public int hashCode() {
-        return name.hashCode() * 37 + type.hashCode();
+        return name.hashCode();
     }
 
     @Override

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1448927&r1=1448926&r2=1448927&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Fri Feb 22 08:11:44 2013
@@ -186,13 +186,18 @@ class Template {
         } else if ("jcr:mixinTypes".equals(name) && mixinTypes != null) {
             return mixinTypes;
         } else {
-            for (int i = 0; i < properties.length; i++) {
-                int diff = name.compareTo(properties[i].getName());
-                if (diff == 0) {
-                    return getProperty(reader, recordId, i);
-                } else if (diff < 0) {
-                    return null;
+            int hash = name.hashCode();
+            int index = 0;
+            while (index < properties.length
+                    && properties[index].getName().hashCode() < hash) {
+                index++;
+            }
+            while (index < properties.length
+                    && properties[index].getName().hashCode() == hash) {
+                if (name.equals(properties[index].getName())) {
+                    return getProperty(reader, recordId, index);
                 }
+                index++;
             }
             return null;
         }
@@ -347,8 +352,13 @@ class Template {
         int afterIndex = 0;
         while (beforeIndex < beforeTemplate.properties.length
                 && afterIndex < properties.length) {
-            int d = properties[afterIndex].compareTo(
-                    beforeTemplate.properties[beforeIndex]);
+            int d = Integer.compare(
+                    properties[afterIndex].hashCode(),
+                    beforeTemplate.properties[beforeIndex].hashCode());
+            if (d == 0) {
+                d = properties[afterIndex].getName().compareTo(
+                        beforeTemplate.properties[beforeIndex].getName());
+            }
             PropertyState beforeProperty = null;
             PropertyState afterProperty = null;
             if (d < 0) {



Mime
View raw message