jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1538202 - /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Date Sat, 02 Nov 2013 14:42:24 GMT
Author: jukka
Date: Sat Nov  2 14:42:24 2013
New Revision: 1538202

URL: http://svn.apache.org/r1538202
Log:
OAK-1142: Optimize node builders for the common case where there are no transient changes

Better tracking of the base state over set/reset

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java?rev=1538202&r1=1538201&r2=1538202&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/memory/MemoryNodeBuilder.java
Sat Nov  2 14:42:24 2013
@@ -32,6 +32,7 @@ import javax.annotation.Nonnull;
 
 import com.google.common.base.Objects;
 import com.google.common.io.ByteStreams;
+
 import org.apache.jackrabbit.oak.api.Blob;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.api.Type;
@@ -222,9 +223,9 @@ public class MemoryNodeBuilder implement
      * @param newBase new base state
      */
     public void reset(NodeState newBase) {
+        checkState(parent == null);
         base = checkNotNull(newBase);
-        baseRevision++;
-        head().setState(newBase);
+        baseRevision = rootHead().setState(newBase) + 1;
     }
 
     /**
@@ -234,8 +235,9 @@ public class MemoryNodeBuilder implement
      * @param newHead new head state
      */
     protected void set(NodeState newHead) {
-        baseRevision++; // this forces all sub-builders to refresh their heads
-        head().setState(newHead);
+        checkState(parent == null);
+        // updating the base revision forces all sub-builders to refresh
+        baseRevision = rootHead().setState(newHead);
     }
 
     //--------------------------------------------------------< NodeBuilder >---
@@ -518,14 +520,10 @@ public class MemoryNodeBuilder implement
          */
         public abstract boolean isModified();
 
-        public void setState(NodeState state) {
-            throw new IllegalStateException("Cannot set the state of a non-root builder");
-        }
-
     }
 
     private class UnconnectedHead extends Head {
-        private long revision = 0;
+        private long revision = baseRevision;
         private NodeState state = base;
 
         @Override
@@ -636,10 +634,11 @@ public class MemoryNodeBuilder implement
             return this;
         }
 
-        @Override
-        public final void setState(NodeState state) {
+        public final long setState(NodeState state) {
             this.state = new MutableNodeState(state);
-            revision++;
+            // To be able to make a distinction between set() and reset(), we
+            revision++;          // increment the revision twice and
+            return revision++;   // return the intermediate value
         }
 
     }



Mime
View raw message