jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1359216 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Date Mon, 09 Jul 2012 15:25:21 GMT
Author: jukka
Date: Mon Jul  9 15:25:21 2012
New Revision: 1359216

URL: http://svn.apache.org/viewvc?rev=1359216&view=rev
Log:
OAK-172: Optimize KernelNodeState equality checks

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1359216&r1=1359215&r2=1359216&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Mon Jul  9 15:25:21 2012
@@ -43,7 +43,7 @@ import java.util.Map.Entry;
  * Basic {@link NodeState} implementation based on the {@link MicroKernel}
  * interface. This class makes an attempt to load data lazily.
  */
-class KernelNodeState extends AbstractNodeState {
+final class KernelNodeState extends AbstractNodeState {
 
     /**
      * Maximum number of child nodes kept in memory.
@@ -61,6 +61,8 @@ class KernelNodeState extends AbstractNo
 
     private long childNodeCount = -1;
 
+    private String hash = null;
+
     // TODO: WeakReference?
     private Map<String, NodeState> childNodes;
 
@@ -89,7 +91,8 @@ class KernelNodeState extends AbstractNo
     private synchronized void init() {
         if (properties == null) {
             String json = kernel.getNodes(
-                    path, revision, 0, 0, MAX_CHILD_NODE_NAMES, null);
+                    path, revision, 0, 0, MAX_CHILD_NODE_NAMES,
+                    "{properties:[\"*\",\":hash\"]}");
 
             JsopReader reader = new JsopTokenizer(json);
             reader.read('{');
@@ -101,6 +104,8 @@ class KernelNodeState extends AbstractNo
                 if (":childNodeCount".equals(name)) {
                     childNodeCount =
                             Long.valueOf(reader.read(JsopReader.NUMBER));
+                } else if (":hash".equals(name)) {
+                    hash = reader.read(JsopReader.STRING);
                 } else if (reader.matches('{')) {
                     reader.read('}');
                     String childPath = path + '/' + name;
@@ -173,6 +178,33 @@ class KernelNodeState extends AbstractNo
         };
     }
 
+    //------------------------------------------------------------< Object >--
+
+    @Override
+    public boolean equals(Object object) {
+        if (this == object) {
+            return true;
+        } else if (object instanceof KernelNodeState) {
+            KernelNodeState that = (KernelNodeState) object;
+            // When both instances come from the same MicroKernel, we can
+            // use revision/path information or content hashes (when available)
+            // to avoid a full tree comparison in many cases.
+            if (kernel.equals(that.kernel)) {
+                if (revision.equals(that.revision) && path.equals(that.path)) {
+                    return true;
+                } else {
+                    this.init();
+                    that.init();
+                    if (hash != null && that.hash != null) {
+                        return hash.equals(that.hash);
+                    }
+                }
+            }
+        }
+        // fallback
+        return super.equals(object);
+    }
+
     //------------------------------------------------------------< internal >---
 
     @Nonnull
@@ -251,12 +283,4 @@ class KernelNodeState extends AbstractNo
         }
     }
 
-    private List<CoreValue> readArray(JsopReader reader) {
-        List<CoreValue> values = new ArrayList<CoreValue>();
-        while (!reader.matches(']')) {
-            values.add(CoreValueMapper.fromJsopReader(reader, valueFactory));
-            reader.matches(',');
-        }
-        return values;
-    }
-}
\ No newline at end of file
+}



Mime
View raw message