jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1364121 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak: core/TreeImpl.java plugins/memory/MemoryNodeStateBuilder.java spi/state/NodeStateBuilder.java
Date Sat, 21 Jul 2012 16:42:59 GMT
Author: jukka
Date: Sat Jul 21 16:42:58 2012
New Revision: 1364121

URL: http://svn.apache.org/viewvc?rev=1364121&view=rev
Log:
OAK-175: MemoryNodeStateBuilder inefficient for large child node lists

Add NodeStateBuilder.hasChildNode() and .getChildNodeNames() to reduce the number of .getNodeState()
calls.

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java?rev=1364121&r1=1364120&r2=1364121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Sat Jul 21 16:42:58 2012
@@ -32,7 +32,6 @@ import org.apache.jackrabbit.oak.api.Cor
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.core.RootImpl.PurgeListener;
-import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 import org.apache.jackrabbit.oak.spi.state.NodeStateDiff;
@@ -214,7 +213,7 @@ public class TreeImpl implements Tree, P
 
     @Override
     public boolean hasChild(String name) {
-        return getNodeState().getChildNode(name) != null;
+        return getNodeStateBuilder().hasChildNode(name);
     }
 
     @Override
@@ -225,15 +224,14 @@ public class TreeImpl implements Tree, P
     @Override
     public Iterable<Tree> getChildren() {
         return Iterables.transform(
-                getNodeState().getChildNodeEntries(),
-                new Function<ChildNodeEntry, Tree>() {
+                getNodeStateBuilder().getChildNodeNames(),
+                new Function<String, Tree>() {
                     @Override
-                    public Tree apply(ChildNodeEntry input) {
-                        String childName = input.getName();
-                        TreeImpl child = children.get(childName);
+                    public Tree apply(String input) {
+                        TreeImpl child = children.get(input);
                         if (child == null) {
-                            child = new TreeImpl(root, TreeImpl.this, childName);
-                            children.put(childName, child);
+                            child = new TreeImpl(root, TreeImpl.this, input);
+                            children.put(input, child);
                         }
                         return  child;
                     }

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java?rev=1364121&r1=1364120&r2=1364121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeStateBuilder.java
Sat Jul 21 16:42:58 2012
@@ -18,12 +18,16 @@ package org.apache.jackrabbit.oak.plugin
 
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.PropertyState;
+import org.apache.jackrabbit.oak.spi.state.ChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.NodeState;
 import org.apache.jackrabbit.oak.spi.state.NodeStateBuilder;
 
+import com.google.common.base.Function;
 import com.google.common.base.Predicate;
 import com.google.common.base.Predicates;
+import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
+import com.google.common.collect.Maps;
 
 import java.util.Collections;
 import java.util.HashMap;
@@ -118,6 +122,36 @@ public class MemoryNodeStateBuilder impl
         return count;
     }
 
+    public boolean hasChildNode(String name) {
+        NodeStateBuilder builder = builders.get(name);
+        if (builder != null) {
+            return true;
+        } else if (builders.containsKey(name)) {
+            return false;
+        } else {
+            return base.getChildNode(name) != null;
+        }
+    }
+
+    @Override
+    public Iterable<String> getChildNodeNames() {
+        Iterable<String> unmodified = Iterables.transform(
+                base.getChildNodeEntries(),
+                new Function<ChildNodeEntry, String>() {
+                    @Override
+                    public String apply(ChildNodeEntry input) {
+                        return input.getName();
+                    }
+                });
+        Predicate<String> unmodifiedFilter = Predicates.not(Predicates.in(
+                ImmutableSet.copyOf(builders.keySet())));
+        Set<String> modified = ImmutableSet.copyOf(
+                Maps.filterValues(builders, Predicates.notNull()).keySet());
+        return Iterables.concat(
+                Iterables.filter(unmodified, unmodifiedFilter),
+                modified);
+    }
+
     @Override
     public void setNode(String name, NodeState nodeState) {
         if (nodeState == null) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java?rev=1364121&r1=1364120&r2=1364121&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/spi/state/NodeStateBuilder.java
Sat Jul 21 16:42:58 2012
@@ -45,6 +45,22 @@ public interface NodeStateBuilder {
     long getChildNodeCount();
 
     /**
+     * Checks whether the named child node currently exists.
+     *
+     * @param name child node name
+     * @return {@code true} if the named child node exists,
+     *         {@code false} otherwise
+     */
+    boolean hasChildNode(String name);
+
+    /**
+     * Returns the names of current child nodes.
+     *
+     * @return child node names
+     */
+    Iterable<String> getChildNodeNames();
+
+    /**
      * Add a sub-tree
      *
      * @param name  name child node containing the sub-tree



Mime
View raw message