You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-commits@jackrabbit.apache.org by md...@apache.org on 2013/03/05 16:02:50 UTC
svn commit: r1452837 - in
/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core:
RootImpl.java TreeImpl.java
Author: mduerig
Date: Tue Mar 5 15:02:50 2013
New Revision: 1452837
URL: http://svn.apache.org/r1452837
Log:
OAK-671: Optimise TreeImpl.getBaseState()
Modified:
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/TreeImpl.java
Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java?rev=1452837&r1=1452836&r2=1452837&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java (original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/core/RootImpl.java Tue Mar 5 15:02:50 2013
@@ -226,7 +226,7 @@ public class RootImpl implements Root {
if (!store.getRoot().equals(rootTree.getBaseState())) {
purgePendingChanges();
branch.rebase();
- rootTree = TreeImpl.createRoot(this);
+ rootTree = new TreeImpl(this);
permissionProvider = null;
}
}
@@ -235,7 +235,7 @@ public class RootImpl implements Root {
public final void refresh() {
checkLive();
branch = store.branch();
- rootTree = TreeImpl.createRoot(this);
+ rootTree = new TreeImpl(this);
modCount = 0;
if (permissionProvider != null) {
permissionProvider.refresh();
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=1452837&r1=1452836&r2=1452837&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 Tue Mar 5 15:02:50 2013
@@ -63,6 +63,11 @@ public class TreeImpl implements Tree {
private final NodeBuilder nodeBuilder;
/**
+ * The node state this tree is based on. {@code null} if this is a newly added tree.
+ */
+ private final NodeState baseState;
+
+ /**
* Parent of this tree. Null for the root.
*/
private TreeImpl parent;
@@ -72,10 +77,11 @@ public class TreeImpl implements Tree {
*/
private String name;
- private TreeImpl(RootImpl root) {
+ TreeImpl(RootImpl root) {
this.root = checkNotNull(root);
this.name = "";
this.nodeBuilder = root.createRootBuilder();
+ this.baseState = root.getBaseState();
}
private TreeImpl(RootImpl root, TreeImpl parent, String name) {
@@ -83,16 +89,13 @@ public class TreeImpl implements Tree {
this.parent = checkNotNull(parent);
this.name = checkNotNull(name);
this.nodeBuilder = parent.getNodeBuilder().child(name);
- }
- @Nonnull
- static TreeImpl createRoot(final RootImpl root) {
- return new TreeImpl(root) {
- @Override
- protected NodeState getBaseState() {
- return root.getBaseState();
- }
- };
+ if (parent.baseState == null) {
+ this.baseState = null;
+ }
+ else {
+ this.baseState = parent.baseState.getChildNode(name);
+ }
}
@Override
@@ -410,20 +413,6 @@ public class TreeImpl implements Tree {
return new NodeLocation(this);
}
- //----------------------------------------------------------< protected >---
-
- @CheckForNull
- protected NodeState getBaseState() {
- if (isDisconnected()) {
- throw new IllegalStateException("Cannot get the base state of a disconnected tree");
- }
-
- NodeState parentBaseState = parent.getBaseState();
- return parentBaseState == null
- ? null
- : parentBaseState.getChildNode(name);
- }
-
//-----------------------------------------------------------< internal >---
@Nonnull
@@ -431,6 +420,16 @@ public class TreeImpl implements Tree {
return nodeBuilder;
}
+ @CheckForNull
+ NodeState getBaseState() {
+ return baseState;
+ }
+
+ @Nonnull
+ NodeState getNodeState() {
+ return nodeBuilder.getNodeState();
+ }
+
/**
* Move this tree to the parent at {@code destParent} with the new name
* {@code destName}.
@@ -447,11 +446,6 @@ public class TreeImpl implements Tree {
parent = destParent;
}
- @Nonnull
- NodeState getNodeState() {
- return nodeBuilder.getNodeState();
- }
-
/**
* Get a tree for the tree identified by {@code path}.
*