jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1527644 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: SegmentWriter.java Template.java
Date Mon, 30 Sep 2013 16:42:24 GMT
Author: jukka
Date: Mon Sep 30 16:42:24 2013
New Revision: 1527644

URL: http://svn.apache.org/r1527644
Log:
OAK-1031: SegmentMK: Fewer segment lookups

Remove Template methods that are no longer used

Modified:
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
    jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java?rev=1527644&r1=1527643&r2=1527644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/SegmentWriter.java
Mon Sep 30 16:42:24 2013
@@ -643,12 +643,13 @@ public class SegmentWriter {
                 }
 
                 RecordId childNameId = null;
-                if (template.hasNoChildNodes()) {
+                String childName = template.getChildName();
+                if (childName == Template.ZERO_CHILD_NODES) {
                     head |= 1 << 29;
-                } else if (template.hasManyChildNodes()) {
+                } else if (childName == Template.MANY_CHILD_NODES) {
                     head |= 1 << 28;
                 } else {
-                    childNameId = writeString(template.getChildName());
+                    childNameId = writeString(childName);
                     ids.add(childNameId);
                 }
 
@@ -720,7 +721,8 @@ public class SegmentWriter {
         List<RecordId> ids = Lists.newArrayList();
         ids.add(templateId);
 
-        if (template.hasManyChildNodes()) {
+        String childName = template.getChildName();
+        if (childName == Template.MANY_CHILD_NODES) {
             MapRecord base;
             final Map<String, RecordId> childNodes = Maps.newHashMap();
             if (before != null
@@ -754,7 +756,7 @@ public class SegmentWriter {
                 }
             }
             ids.add(writeMap(base, childNodes).getRecordId());
-        } else if (!template.hasNoChildNodes()) {
+        } else if (childName != Template.ZERO_CHILD_NODES) {
             ids.add(writeNode(state.getChildNode(template.getChildName())).getRecordId());
         }
 

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java?rev=1527644&r1=1527643&r2=1527644&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/Template.java
Mon Sep 30 16:42:24 2013
@@ -19,8 +19,6 @@ package org.apache.jackrabbit.oak.plugin
 import static com.google.common.base.Preconditions.checkElementIndex;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Preconditions.checkState;
-import static org.apache.jackrabbit.JcrConstants.JCR_MIXINTYPES;
-import static org.apache.jackrabbit.JcrConstants.JCR_PRIMARYTYPE;
 import static org.apache.jackrabbit.oak.plugins.memory.EmptyNodeState.MISSING_NODE;
 import static org.apache.jackrabbit.oak.plugins.segment.Segment.RECORD_ID_BYTES;
 
@@ -158,86 +156,17 @@ public class Template {
         return null;
     }
 
-    public boolean hasNoChildNodes() {
-        return childName == ZERO_CHILD_NODES;
-    }
-
-    public boolean hasOneChildNode() {
-        return !hasNoChildNodes() && !hasManyChildNodes();
-    }
-
-    public boolean hasManyChildNodes() {
-        return childName == MANY_CHILD_NODES;
-    }
-
     String getChildName() {
         return childName;
     }
 
-    int getPropertyCount() {
-        if (primaryType != null && mixinTypes != null) {
-            return properties.length + 2;
-        } else if (primaryType != null || mixinTypes != null) {
-            return properties.length + 1;
-        } else {
-            return properties.length;
-        }
-    }
-
-    public boolean hasProperty(String name) {
-        if (JCR_PRIMARYTYPE.equals(name)) {
-            return primaryType != null;
-        } else if (JCR_MIXINTYPES.equals(name)) {
-            return mixinTypes != null;
-        } else {
-            int hash = name.hashCode();
-            int index = 0;
-            while (index < properties.length
-                    && properties[index].getName().hashCode() < hash) {
-                index++;
-            }
-            while (index < properties.length
-                    && properties[index].getName().hashCode() == hash) {
-                if (name.equals(properties[index].getName())) {
-                    return true;
-                }
-                index++;
-            }
-            return false;
-        }
-    }
-
-    public PropertyState getProperty(
-            String name, Segment segment, RecordId recordId) {
-        if (JCR_PRIMARYTYPE.equals(name) && primaryType != null) {
-            return primaryType;
-        } else if (JCR_MIXINTYPES.equals(name) && mixinTypes != null) {
-            return mixinTypes;
-        } else {
-            int hash = name.hashCode();
-            int index = 0;
-            while (index < properties.length
-                    && properties[index].getName().hashCode() < hash) {
-                index++;
-            }
-            while (index < properties.length
-                    && properties[index].getName().hashCode() == hash) {
-                if (name.equals(properties[index].getName())) {
-                    return getProperty(segment, recordId, index);
-                }
-                index++;
-            }
-            return null;
-        }
-    }
-
     private PropertyState getProperty(
             Segment segment, RecordId recordId, int index) {
         checkElementIndex(index, properties.length);
         segment = checkNotNull(segment).getSegment(checkNotNull(recordId));
 
         int offset = recordId.getOffset() + RECORD_ID_BYTES;
-        if (!hasNoChildNodes()) {
+        if (childName != ZERO_CHILD_NODES) {
             offset += RECORD_ID_BYTES;
         }
         offset += index * RECORD_ID_BYTES;
@@ -245,32 +174,8 @@ public class Template {
                 segment, segment.readRecordId(offset), properties[index]);
     }
 
-    public Iterable<PropertyState> getProperties(
-            Segment segment, RecordId recordId) {
-        List<PropertyState> list =
-                Lists.newArrayListWithCapacity(properties.length + 2);
-        if (primaryType != null) {
-            list.add(primaryType);
-        }
-        if (mixinTypes != null) {
-            list.add(mixinTypes);
-        }
-        int offset = recordId.getOffset() + RECORD_ID_BYTES;
-        if (!hasNoChildNodes()) {
-            offset += RECORD_ID_BYTES;
-        }
-        segment = segment.getSegment(recordId);
-        for (int i = 0; i < properties.length; i++) {
-            RecordId propertyId = segment.readRecordId(offset);
-            list.add(new SegmentPropertyState(
-                    segment, propertyId, properties[i]));
-            offset += RECORD_ID_BYTES;
-        }
-        return list;
-    }
-
     MapRecord getChildNodeMap(Segment segment, RecordId recordId) {
-        checkState(hasManyChildNodes());
+        checkState(childName != ZERO_CHILD_NODES);
         segment = segment.getSegment(recordId);
         int offset = recordId.getOffset() + RECORD_ID_BYTES;
         RecordId childNodesId = segment.readRecordId(offset);
@@ -279,9 +184,9 @@ public class Template {
 
     public NodeState getChildNode(
             String name, Segment segment, RecordId recordId) {
-        if (hasNoChildNodes()) {
+        if (childName == ZERO_CHILD_NODES) {
             return MISSING_NODE;
-        } else if (hasManyChildNodes()) {
+        } else if (childName == MANY_CHILD_NODES) {
             MapRecord map = getChildNodeMap(segment, recordId);
             RecordId childNodeId = map.getEntry(name);
             if (childNodeId != null) {
@@ -301,9 +206,9 @@ public class Template {
 
     Iterable<? extends ChildNodeEntry> getChildNodeEntries(
             Segment segment, RecordId recordId) {
-        if (hasNoChildNodes()) {
+        if (childName == ZERO_CHILD_NODES) {
             return Collections.emptyList();
-        } else if (hasManyChildNodes()) {
+        } else if (childName == MANY_CHILD_NODES) {
             MapRecord map = getChildNodeMap(segment, recordId);
             return map.getEntries();
         } else {
@@ -330,9 +235,9 @@ public class Template {
         }
 
         // Compare child nodes
-        if (hasNoChildNodes()) {
+        if (childName == ZERO_CHILD_NODES) {
             return true;
-        } else if (hasOneChildNode()) {
+        } else if (childName != MANY_CHILD_NODES) {
             NodeState thisChild = getChildNode(childName, thisSegment, thisId);
             NodeState thatChild = getChildNode(childName, thatSegment, thatId);
             return thisChild.equals(thatChild);
@@ -422,17 +327,17 @@ public class Template {
             }
         }
 
-        if (hasNoChildNodes()) {
-            if (!beforeTemplate.hasNoChildNodes()) {
-                for (ChildNodeEntry entry :
-                        beforeTemplate.getChildNodeEntries(beforeSegment, beforeId)) {
+        if (childName == ZERO_CHILD_NODES) {
+            if (beforeTemplate.childName != ZERO_CHILD_NODES) {
+                for (ChildNodeEntry entry : beforeTemplate.getChildNodeEntries(
+                        beforeSegment, beforeId)) {
                     if (!diff.childNodeDeleted(
                             entry.getName(), entry.getNodeState())) {
                         return false;
                     }
                 }
             }
-        } else if (hasOneChildNode()) {
+        } else if (childName != MANY_CHILD_NODES) {
             NodeState afterNode = getChildNode(childName, afterSegment, afterId);
             NodeState beforeNode = beforeTemplate.getChildNode(
                     childName, beforeSegment, beforeId);
@@ -445,8 +350,9 @@ public class Template {
                     return false;
                 }
             }
-            if ((beforeTemplate.hasOneChildNode() && !beforeNode.exists())
-                    || beforeTemplate.hasManyChildNodes()) {
+            if (beforeTemplate.childName == MANY_CHILD_NODES
+                    || (beforeTemplate.childName != ZERO_CHILD_NODES
+                        && !beforeNode.exists())) {
                 for (ChildNodeEntry entry :
                     beforeTemplate.getChildNodeEntries(beforeSegment, beforeId)) {
                     if (!childName.equals(entry.getName())) {
@@ -457,15 +363,15 @@ public class Template {
                     }
                 }
             }
-        } else if (beforeTemplate.hasNoChildNodes()) {
+        } else if (beforeTemplate.childName == ZERO_CHILD_NODES) {
             for (ChildNodeEntry entry : getChildNodeEntries(afterSegment, afterId)) {
                 if (!diff.childNodeAdded(
                         entry.getName(), entry.getNodeState())) {
                     return false;
                 }
             }
-        } else if (beforeTemplate.hasOneChildNode()) {
-            String name = beforeTemplate.getChildName();
+        } else if (beforeTemplate.childName != MANY_CHILD_NODES) {
+            String name = beforeTemplate.childName;
             for (ChildNodeEntry entry : getChildNodeEntries(afterSegment, afterId)) {
                 String childName = entry.getName();
                 NodeState afterChild = entry.getNodeState();
@@ -637,9 +543,9 @@ public class Template {
             builder.append(properties[i]);
             builder.append(" = ?, ");
         }
-        if (hasNoChildNodes()) {
+        if (childName == ZERO_CHILD_NODES) {
             builder.append("<no children>");
-        } else if (hasManyChildNodes()) {
+        } else if (childName == MANY_CHILD_NODES) {
             builder.append("<many children>");
         } else {
             builder.append(childName + " = <node>");



Mime
View raw message