jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1486911 - in /jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr: NodeImpl.java delegate/NodeDelegate.java
Date Tue, 28 May 2013 12:41:58 GMT
Author: jukka
Date: Tue May 28 12:41:58 2013
New Revision: 1486911

URL: http://svn.apache.org/r1486911
Log:
OAK-839: Optimization in the Node#getNodes

Improvement based on the patch by Antonio Sanso

Modified:
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
    jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java?rev=1486911&r1=1486910&r2=1486911&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/NodeImpl.java
Tue May 28 12:41:58 2013
@@ -502,8 +502,21 @@ public class NodeImpl<T extends NodeDele
             @Override
             public NodeIterator perform() throws RepositoryException {
                 Iterator<NodeDelegate> children = dlg.getChildren();
-                long size = dlg.getChildCount();
-                return new NodeIteratorAdapter(nodeIterator(children), size);
+                return new NodeIteratorAdapter(nodeIterator(children)) {
+                    private long size = -1;
+                    @Override
+                    public long getSize() {
+                        if (size == -1) {
+                            try {
+                                size = dlg.getChildCount();
+                            } catch (InvalidItemStateException e) {
+                                throw new IllegalStateException(
+                                        "This iterator is no longer valid", e);
+                            }
+                        }
+                        return size;
+                    }
+                };
             }
         });
     }

Modified: jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java?rev=1486911&r1=1486910&r2=1486911&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
(original)
+++ jackrabbit/oak/trunk/oak-jcr/src/main/java/org/apache/jackrabbit/oak/jcr/delegate/NodeDelegate.java
Tue May 28 12:41:58 2013
@@ -61,7 +61,6 @@ import static org.apache.jackrabbit.oak.
 import static org.apache.jackrabbit.oak.plugins.nodetype.NodeTypeConstants.OAK_SUPERTYPES;
 
 import java.util.Calendar;
-import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
@@ -77,6 +76,7 @@ import javax.jcr.nodetype.NoSuchNodeType
 
 import com.google.common.base.Function;
 import com.google.common.base.Predicate;
+
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Tree;
 import org.apache.jackrabbit.oak.api.Tree.Status;
@@ -338,23 +338,20 @@ public class NodeDelegate extends ItemDe
      */
     @Nonnull
     public Iterator<NodeDelegate> getChildren() throws InvalidItemStateException {
-        Tree tree = getTree();
-        long count = tree.getChildrenCount();
-        if (count == 0) {
-            // Optimise the most common case
-            return Collections.<NodeDelegate>emptySet().iterator();
-        } else if (count == 1) {
-            // Optimise another typical case
-            Tree child = tree.getChildren().iterator().next();
-            if (!child.getName().startsWith(":")) {
-                NodeDelegate delegate = new NodeDelegate(sessionDelegate, child);
-                return Collections.singleton(delegate).iterator();
-            } else {
-                return Collections.<NodeDelegate>emptySet().iterator();
-            }
-        } else {
-            return nodeDelegateIterator(tree.getChildren().iterator());
-        }
+        Iterator<Tree> iterator = getTree().getChildren().iterator();
+        return transform(
+                filter(iterator, new Predicate<Tree>() {
+                    @Override
+                    public boolean apply(Tree tree) {
+                        return !tree.getName().startsWith(":");
+                    }
+                }),
+                new Function<Tree, NodeDelegate>() {
+                    @Override
+                    public NodeDelegate apply(Tree tree) {
+                        return new NodeDelegate(sessionDelegate, tree);
+                    }
+                });
     }
 
     public void orderBefore(String source, String target)
@@ -700,23 +697,6 @@ public class NodeDelegate extends ItemDe
         return TreeUtil.getTree(tree, relPath);
     }
 
-    private Iterator<NodeDelegate> nodeDelegateIterator(
-            Iterator<Tree> children) {
-        return transform(
-                filter(children, new Predicate<Tree>() {
-                    @Override
-                    public boolean apply(Tree tree) {
-                        return !tree.getName().startsWith(":");
-                    }
-                }),
-                new Function<Tree, NodeDelegate>() {
-                    @Override
-                    public NodeDelegate apply(Tree tree) {
-                        return new NodeDelegate(sessionDelegate, tree);
-                    }
-                });
-    }
-
     // Generic property value accessors. TODO: add to Tree?
 
     private static boolean getBoolean(Tree tree, String name) {



Mime
View raw message