jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1359541 - in /jackrabbit/oak/trunk/oak-core/src: main/java/org/apache/jackrabbit/oak/kernel/ test/java/org/apache/jackrabbit/oak/kernel/
Date Tue, 10 Jul 2012 09:42:19 GMT
Author: jukka
Date: Tue Jul 10 09:42:18 2012
New Revision: 1359541

URL: http://svn.apache.org/viewvc?rev=1359541&view=rev
Log:
OAK-176: Reduce CoreValueFactoryImpl footprint

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/CoreValueMapper.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
    jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/CoreValueFactoryTest.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/CoreValueMapper.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/CoreValueMapper.java?rev=1359541&r1=1359540&r2=1359541&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/CoreValueMapper.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/CoreValueMapper.java
Tue Jul 10 09:42:18 2012
@@ -23,6 +23,7 @@ import java.util.Map;
 
 import javax.jcr.PropertyType;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.oak.api.CoreValue;
 import org.apache.jackrabbit.oak.api.CoreValueFactory;
@@ -105,30 +106,34 @@ public class CoreValueMapper {
         return sb.toString();
     }
 
+    public static CoreValue fromJsopReader(JsopReader reader, MicroKernel kernel) {
+        return fromJsopReader(reader, new CoreValueFactoryImpl(kernel));
+    }
+
     /**
      * Read a single value from the specified reader and convert it into a
      * {@code CoreValue}. This method takes type-hint prefixes into account.
      *
      * @param reader The JSON reader.
-     * @param valueFactory The factory used to create the value.
+     * @param factory The factory used to create the value.
      * @return The value such as defined by the token obtained from the reader.
      */
-    public static CoreValue fromJsopReader(JsopReader reader, CoreValueFactory valueFactory)
{
+    public static CoreValue fromJsopReader(JsopReader reader, CoreValueFactory factory) {
         CoreValue value;
         if (reader.matches(JsopReader.NUMBER)) {
             String number = reader.getToken();
-            value = valueFactory.createValue(Long.valueOf(number));
+            value = factory.createValue(Long.valueOf(number));
         } else if (reader.matches(JsopReader.TRUE)) {
-            value = valueFactory.createValue(true);
+            value = factory.createValue(true);
         } else if (reader.matches(JsopReader.FALSE)) {
-            value = valueFactory.createValue(false);
+            value = factory.createValue(false);
         } else if (reader.matches(JsopReader.STRING)) {
             String jsonString = reader.getToken();
             if (startsWithHint(jsonString)) {
                 int type = HINT2TYPE.get(jsonString.substring(0, 3));
-                value = valueFactory.createValue(jsonString.substring(4), type);
+                value = factory.createValue(jsonString.substring(4), type);
             } else {
-                value = valueFactory.createValue(jsonString);
+                value = factory.createValue(jsonString);
             }
         } else {
             throw new IllegalArgumentException("Unexpected token: " + reader.getToken());
@@ -144,10 +149,10 @@ public class CoreValueMapper {
      * @param valueFactory The factory used to create the values.
      * @return A list of values such as defined by the reader.
      */
-    public static List<CoreValue> listFromJsopReader(JsopReader reader, CoreValueFactory
valueFactory) {
+    public static List<CoreValue> listFromJsopReader(JsopReader reader, MicroKernel
kernel) {
         List<CoreValue> values = new ArrayList<CoreValue>();
         while (!reader.matches(']')) {
-            values.add(fromJsopReader(reader, valueFactory));
+            values.add(fromJsopReader(reader, kernel));
             reader.matches(',');
         }
         return values;

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java?rev=1359541&r1=1359540&r2=1359541&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeState.java
Tue Jul 10 09:42:18 2012
@@ -22,7 +22,6 @@ import org.apache.jackrabbit.mk.api.Micr
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
 import org.apache.jackrabbit.oak.api.CoreValue;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.plugins.memory.MemoryChildNodeEntry;
 import org.apache.jackrabbit.oak.spi.state.AbstractNodeState;
@@ -52,7 +51,6 @@ final class KernelNodeState extends Abst
     static final int MAX_CHILD_NODE_NAMES = 1000;
 
     private final MicroKernel kernel;
-    private final CoreValueFactory valueFactory;
 
     private final String path;
 
@@ -77,14 +75,12 @@ final class KernelNodeState extends Abst
      * @param path
      * @param revision
      */
-    public KernelNodeState(MicroKernel kernel, CoreValueFactory valueFactory, String path,
String revision) {
+    public KernelNodeState(MicroKernel kernel, String path, String revision) {
         assert kernel != null;
-        assert valueFactory != null;
         assert path != null;
         assert revision != null;
 
         this.kernel = kernel;
-        this.valueFactory = valueFactory;
         this.path = path;
         this.revision = revision;
     }
@@ -113,11 +109,11 @@ final class KernelNodeState extends Abst
                     if ("/".equals(path)) {
                         childPath = '/' + name;
                     }
-                    childNodes.put(name, new KernelNodeState(kernel, valueFactory, childPath,
revision));
+                    childNodes.put(name, new KernelNodeState(kernel, childPath, revision));
                 } else if (reader.matches('[')) {
-                    properties.put(name, new PropertyStateImpl(name, CoreValueMapper.listFromJsopReader(reader,
valueFactory)));
+                    properties.put(name, new PropertyStateImpl(name, CoreValueMapper.listFromJsopReader(reader,
kernel)));
                 } else {
-                    CoreValue cv = CoreValueMapper.fromJsopReader(reader, valueFactory);
+                    CoreValue cv = CoreValueMapper.fromJsopReader(reader, kernel);
                     properties.put(name, new PropertyStateImpl(name, cv));
                 }
             } while (reader.matches(','));
@@ -157,7 +153,7 @@ final class KernelNodeState extends Abst
         if (child == null && childNodeCount > MAX_CHILD_NODE_NAMES) {
             String childPath = getChildPath(name);
             if (kernel.nodeExists(childPath, revision)) {
-                child = new KernelNodeState(kernel, valueFactory, childPath, revision);
+                child = new KernelNodeState(kernel, childPath, revision);
             }
         }
         return child;
@@ -300,8 +296,8 @@ final class KernelNodeState extends Abst
                 if (reader.matches('{')) {
                     reader.read('}');
                     String childPath = getChildPath(name);
-                    NodeState child = new KernelNodeState(
-                            kernel, valueFactory, childPath, revision);
+                    NodeState child =
+                            new KernelNodeState(kernel, childPath, revision);
                     entries.add(new MemoryChildNodeEntry(name, child));
                 } else {
                     reader.read();

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java?rev=1359541&r1=1359540&r2=1359541&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStore.java
Tue Jul 10 09:42:18 2012
@@ -51,11 +51,6 @@ public class KernelNodeStore extends Mem
     private volatile Observer observer = EmptyObserver.INSTANCE;
 
     /**
-     * Value factory backed by the {@link #kernel} instance.
-     */
-    private final CoreValueFactory valueFactory;
-
-    /**
      * State of the current root node.
      */
     private KernelNodeState root;
@@ -63,9 +58,7 @@ public class KernelNodeStore extends Mem
     public KernelNodeStore(MicroKernel kernel) {
         assert kernel != null;
         this.kernel = kernel;
-        this.valueFactory = new CoreValueFactoryImpl(kernel);
-        this.root = new KernelNodeState(
-                kernel, valueFactory, "/", kernel.getHeadRevision());
+        this.root = new KernelNodeState(kernel, "/", kernel.getHeadRevision());
     }
 
     public CommitEditor getEditor() {
@@ -93,8 +86,7 @@ public class KernelNodeStore extends Mem
         String revision = kernel.getHeadRevision();
         if (!revision.equals(root.getRevision())) {
             NodeState before = root;
-            root = new KernelNodeState(
-                    kernel, valueFactory, "/", kernel.getHeadRevision());
+            root = new KernelNodeState(kernel, "/", kernel.getHeadRevision());
             observer.contentChanged(this, before, root);
         }
         return root;
@@ -107,7 +99,7 @@ public class KernelNodeStore extends Mem
 
     @Override
     public CoreValueFactory getValueFactory() {
-        return valueFactory;
+        return new CoreValueFactoryImpl(kernel);
     }
 
     //------------------------------------------------------------< internal >---

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java?rev=1359541&r1=1359540&r2=1359541&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/kernel/KernelNodeStoreBranch.java
Tue Jul 10 09:42:18 2012
@@ -19,7 +19,6 @@ package org.apache.jackrabbit.oak.kernel
 import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.api.MicroKernelException;
 import org.apache.jackrabbit.oak.api.CommitFailedException;
-import org.apache.jackrabbit.oak.api.CoreValueFactory;
 import org.apache.jackrabbit.oak.api.PropertyState;
 import org.apache.jackrabbit.oak.commons.PathUtils;
 import org.apache.jackrabbit.oak.spi.commit.CommitEditor;
@@ -59,7 +58,7 @@ class KernelNodeStoreBranch implements N
 
         MicroKernel kernel = store.getKernel();
         this.branchRevision = kernel.branch(null);
-        this.currentRoot = new KernelNodeState(kernel, getValueFactory(), "/", branchRevision);
+        this.currentRoot = new KernelNodeState(kernel, "/", branchRevision);
         this.base = currentRoot;
         this.committed = currentRoot;
     }
@@ -134,7 +133,7 @@ class KernelNodeStoreBranch implements N
             branchRevision = null;
             currentRoot = null;
             committed = null;
-            KernelNodeState committed = new KernelNodeState(kernel, getValueFactory(), "/",
mergedRevision);
+            KernelNodeState committed = new KernelNodeState(kernel, "/", mergedRevision);
             return committed;
         }
         catch (MicroKernelException e) {
@@ -144,10 +143,6 @@ class KernelNodeStoreBranch implements N
 
     //------------------------------------------------------------< private >---
 
-    private CoreValueFactory getValueFactory() {
-        return store.getValueFactory();
-    }
-
     private NodeState getNode(String path) {
         NodeState node = getRoot();
         for (String name : elements(path)) {
@@ -163,7 +158,7 @@ class KernelNodeStoreBranch implements N
     private void commit(String jsop) {
         MicroKernel kernel = store.getKernel();
         branchRevision = kernel.commit("/", jsop, branchRevision, null);
-        currentRoot = new KernelNodeState(kernel, getValueFactory(), "/", branchRevision);
+        currentRoot = new KernelNodeState(kernel, "/", branchRevision);
         committed = currentRoot;
     }
 

Modified: jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/CoreValueFactoryTest.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/CoreValueFactoryTest.java?rev=1359541&r1=1359540&r2=1359541&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/CoreValueFactoryTest.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/test/java/org/apache/jackrabbit/oak/kernel/CoreValueFactoryTest.java
Tue Jul 10 09:42:18 2012
@@ -16,6 +16,7 @@
  */
 package org.apache.jackrabbit.oak.kernel;
 
+import org.apache.jackrabbit.mk.api.MicroKernel;
 import org.apache.jackrabbit.mk.core.MicroKernelImpl;
 import org.apache.jackrabbit.mk.json.JsopReader;
 import org.apache.jackrabbit.mk.json.JsopTokenizer;
@@ -42,8 +43,10 @@ import static org.junit.Assert.assertEqu
  */
 public class CoreValueFactoryTest {
 
+    private final MicroKernel kernel = new MicroKernelImpl();
+
     private final CoreValueFactory valueFactory =
-            new CoreValueFactoryImpl(new MicroKernelImpl());
+            new CoreValueFactoryImpl(kernel);
 
     private Map<CoreValue, String> singleValueMap;
 
@@ -151,7 +154,7 @@ public class CoreValueFactoryTest {
         for (CoreValue v : singleValueMap.keySet()) {
             String json = singleValueMap.get(v);
             JsopReader reader = new JsopTokenizer(json);
-            assertEquals(v, CoreValueMapper.fromJsopReader(reader, valueFactory));
+            assertEquals(v, CoreValueMapper.fromJsopReader(reader, kernel));
         }
     }
 
@@ -169,7 +172,7 @@ public class CoreValueFactoryTest {
             List<CoreValue> values = mvValueMap.get(json);
             JsopReader reader = new JsopTokenizer(json);
             if (reader.matches('[')) {
-                assertEquals(values, CoreValueMapper.listFromJsopReader(reader, valueFactory));
+                assertEquals(values, CoreValueMapper.listFromJsopReader(reader, kernel));
             }
         }
     }



Mime
View raw message