Author: jukka
Date: Wed Mar 19 19:17:35 2014
New Revision: 1579360
URL: http://svn.apache.org/r1579360
Log:
OAK-850: Degrade gracefully when :childOrder is out of sync
Optimize the ordered getChildNames() operation for the common case where the
child order list is in sync with the actual child nodes
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/AbstractTree.java
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/AbstractTree.java
URL:
http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/AbstractTree.java?rev=1579360&r1=1579359&r2=1579360&view=diff
==============================================================================
---
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/AbstractTree.java
(original)
+++
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/tree/AbstractTree.java
Wed Mar 19 19:17:35 2014
@@ -23,6 +23,7 @@ import static com.google.common.base.Pre
import static com.google.common.collect.Iterables.filter;
import static com.google.common.collect.Iterables.size;
import static com.google.common.collect.Iterables.transform;
+import static com.google.common.collect.Lists.newArrayListWithCapacity;
import static com.google.common.collect.Sets.newLinkedHashSet;
import static org.apache.jackrabbit.oak.api.Tree.Status.MODIFIED;
import static org.apache.jackrabbit.oak.api.Tree.Status.NEW;
@@ -31,6 +32,7 @@ import static org.apache.jackrabbit.oak.
import static
org.apache.jackrabbit.oak.plugins.tree.TreeConstants.OAK_CHILD_ORDER;
import static org.apache.jackrabbit.oak.spi.state.NodeStateUtils.isHidden;
+import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
@@ -133,9 +135,15 @@ public abstract class AbstractTree imple
PropertyState order = nodeBuilder.getProperty(OAK_CHILD_ORDER);
if (order != null && order.getType() == NAMES) {
Set<String> names =
newLinkedHashSet(nodeBuilder.getChildNodeNames());
- Set<String> ordered = newLinkedHashSet(order.getValue(NAMES));
- ordered.retainAll(names); // remove names of missing child nodes
- ordered.addAll(names); // insert names of unordered child nodes
+ List<String> ordered = newArrayListWithCapacity(names.size());
+ for (String name : order.getValue(NAMES)) {
+ // only include names of child nodes that actually exist
+ if (names.remove(name)) {
+ ordered.add(name);
+ }
+ }
+ // add names of child nodes that are not explicitly ordered
+ ordered.addAll(names);
return ordered;
} else {
return nodeBuilder.getChildNodeNames();