jackrabbit-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From thom...@apache.org
Subject svn commit: r1235673 - in /jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem: NodeImpl.java NodeListLarge.java NodeListSmall.java NodeListTrie.java Revision.java
Date Wed, 25 Jan 2012 08:22:28 GMT
Author: thomasm
Date: Wed Jan 25 08:22:27 2012
New Revision: 1235673

URL: http://svn.apache.org/viewvc?rev=1235673&view=rev
Log:
Small child node lists are orderable, large lists are not.

Removed:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListLarge.java
Modified:
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListTrie.java
    jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java?rev=1235673&r1=1235672&r2=1235673&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeImpl.java
Wed Jan 25 08:22:27 2012
@@ -623,11 +623,7 @@ public class NodeImpl implements Cache.V
                 String value = t.readRawValue();
                 if (key.length() > 0 && key.charAt(0) == ':') {
                     if (key.equals(CHILDREN)) {
-                        if (MemoryKernelImpl.SORT_CHILDREN) {
-                            node.childNodes = NodeListTrie.read(t, map, value);
-                        } else {
-                            node.childNodes = NodeListLarge.read(t, map, value);
-                        }
+                        node.childNodes = NodeListTrie.read(t, map, value);
                     } else if (key.equals(DESCENDANT_COUNT)) {
                         node.descendantCount = Long.parseLong(value);
                         descendantCountSet = true;

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java?rev=1235673&r1=1235672&r2=1235673&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListSmall.java
Wed Jan 25 08:22:27 2012
@@ -58,51 +58,27 @@ public class NodeListSmall implements No
     }
 
     private int find(String name) {
-        if (MemoryKernelImpl.SORT_CHILDREN) {
-            // copy, to avoid concurrency issues
-            int last = lastNameIndexCache;
-            if (last < size && names[last].equals(name)) {
-                return last;
+        // copy, to avoid concurrency issues
+        int last = lastNameIndexCache;
+        if (last < size && names[sort[last]].equals(name)) {
+            return last;
+        }
+        int min = 0, max = size - 1;
+        while (min <= max) {
+            int test = (min + max) >>> 1;
+            int compare = names[sort[test]].compareTo(name);
+            if (compare == 0) {
+                lastNameIndexCache = test;
+                return test;
+            }
+            if (compare > 0) {
+                max = test - 1;
+            } else if (compare < 0) {
+                min = test + 1;
             }
-            int min = 0, max = size - 1;
-            while (min <= max) {
-                int test = (min + max) >>> 1;
-                int compare = names[test].compareTo(name);
-                if (compare == 0) {
-                    lastNameIndexCache = test;
-                    return test;
-                }
-                if (compare > 0) {
-                    max = test - 1;
-                } else if (compare < 0) {
-                    min = test + 1;
-                }
-            }
-            // not found: return negative insertion point
-            return -(min + 1);
-        } else {
-            // copy, to avoid concurrency issues
-            int last = lastNameIndexCache;
-            if (last < size && names[sort[last]].equals(name)) {
-                return last;
-            }
-            int min = 0, max = size - 1;
-            while (min <= max) {
-                int test = (min + max) >>> 1;
-                int compare = names[sort[test]].compareTo(name);
-                if (compare == 0) {
-                    lastNameIndexCache = test;
-                    return test;
-                }
-                if (compare > 0) {
-                    max = test - 1;
-                } else if (compare < 0) {
-                    min = test + 1;
-                }
-            }
-            // not found: return negative insertion point
-            return -(min + 1);
         }
+        // not found: return negative insertion point
+        return -(min + 1);
     }
 
     public NodeId get(String name) {
@@ -110,11 +86,7 @@ public class NodeListSmall implements No
         if (index < 0) {
             throw ExceptionFactory.get("Node not found: " + name);
         }
-        if (MemoryKernelImpl.SORT_CHILDREN) {
-            return children[index];
-        } else {
-            return children[sort[index]];
-        }
+        return children[sort[index]];
     }
 
     public void add(String name, NodeId x) {
@@ -124,14 +96,9 @@ public class NodeListSmall implements No
         }
         index = -index - 1;
         name = StringCache.cache(name);
-        if (MemoryKernelImpl.SORT_CHILDREN) {
-            names = ArrayUtils.arrayInsert(names, index, name);
-            children = ArrayUtils.arrayInsert(children, index, x);
-        } else {
-            names = ArrayUtils.arrayInsert(names, size, name);
-            children = ArrayUtils.arrayInsert(children, size, x);
-            sort = ArrayUtils.arrayInsert(sort, index, size);
-        }
+        names = ArrayUtils.arrayInsert(names, size, name);
+        children = ArrayUtils.arrayInsert(children, size, x);
+        sort = ArrayUtils.arrayInsert(sort, index, size);
         size++;
     }
 
@@ -161,28 +128,20 @@ public class NodeListSmall implements No
         if (index < 0) {
             throw ExceptionFactory.get("Node not found: " + name);
         }
-        if (MemoryKernelImpl.SORT_CHILDREN) {
-            NodeId result = children[index];
-            names = ArrayUtils.arrayRemove(names, index);
-            children = ArrayUtils.arrayRemove(children, index);
-            size--;
-            return result;
-        } else {
-            int s = sort[index];
-            NodeId result = children[s];
-            names = ArrayUtils.arrayRemove(names, s);
-            children = ArrayUtils.arrayRemove(children, s);
-            sort = ArrayUtils.arrayRemove(sort, index);
-            if (s != size - 1) {
-                for (int i = 0; i < sort.length; i++) {
-                    if (sort[i] >= s) {
-                        sort[i]--;
-                    }
+        int s = sort[index];
+        NodeId result = children[s];
+        names = ArrayUtils.arrayRemove(names, s);
+        children = ArrayUtils.arrayRemove(children, s);
+        sort = ArrayUtils.arrayRemove(sort, index);
+        if (s != size - 1) {
+            for (int i = 0; i < sort.length; i++) {
+                if (sort[i] >= s) {
+                    sort[i]--;
                 }
             }
-            size--;
-            return result;
         }
+        size--;
+        return result;
     }
 
     public String toString() {
@@ -198,11 +157,7 @@ public class NodeListSmall implements No
     public NodeList createClone(NodeMap map, long revId) {
         NodeList result = new NodeListSmall(names, children, sort, size);
         if (size > map.getMaxMemoryChildren()) {
-            if (MemoryKernelImpl.SORT_CHILDREN) {
-                return new NodeListTrie(map, result, size, revId);
-            } else {
-                return new NodeListLarge(map, result, size, revId);
-            }
+            return new NodeListTrie(map, result, size, revId);
         }
         return result;
     }
@@ -245,14 +200,9 @@ public class NodeListSmall implements No
         if (size == 0) {
             return 0;
         }
-        if (MemoryKernelImpl.SORT_CHILDREN) {
-            return Arrays.hashCode(names) ^
-                    Arrays.hashCode(children);
-        } else {
-            return Arrays.hashCode(names) ^
-                    Arrays.hashCode(children) ^
-                    Arrays.hashCode(sort);
-        }
+        return Arrays.hashCode(names) ^
+                Arrays.hashCode(children) ^
+                Arrays.hashCode(sort);
     }
 
     public boolean equals(Object other) {
@@ -265,14 +215,9 @@ public class NodeListSmall implements No
                 if (size == 0) {
                     return true;
                 }
-                if (MemoryKernelImpl.SORT_CHILDREN) {
-                    return Arrays.equals(children, o.children) &&
+                return Arrays.equals(sort, o.sort) &&
+                        Arrays.equals(children, o.children) &&
                         Arrays.equals(names, o.names);
-                } else {
-                    return Arrays.equals(sort, o.sort) &&
-                            Arrays.equals(children, o.children) &&
-                            Arrays.equals(names, o.names);
-                }
             }
         }
         return false;
@@ -281,28 +226,15 @@ public class NodeListSmall implements No
     public void updateHash(NodeMap map, OutputStream out) throws IOException {
         if (children != null) {
             try {
-                if (MemoryKernelImpl.SORT_CHILDREN) {
-                    for (int i = 0, len = names.length; i < len; i++) {
-                        String n = names[i];
-                        IOUtils.writeString(out, n);
-                        NodeId c = children[i];
-                        byte[] hash = c.getHash();
-                        if (hash == null) {
-                            hash = map.getNode(c.getLong()).getHash();
-                        }
-                        out.write(hash);
-                    }
-                } else {
-                    for (int s : sort) {
-                        String n = names[s];
-                        IOUtils.writeString(out, n);
-                        NodeId c = children[s];
-                        byte[] hash = c.getHash();
-                        if (hash == null) {
-                            hash = map.getNode(c.getLong()).getHash();
-                        }
-                        out.write(hash);
+                for (int s : sort) {
+                    String n = names[s];
+                    IOUtils.writeString(out, n);
+                    NodeId c = children[s];
+                    byte[] hash = c.getHash();
+                    if (hash == null) {
+                        hash = map.getNode(c.getLong()).getHash();
                     }
+                    out.write(hash);
                 }
             } catch (UnsupportedEncodingException e) {
                 throw new RuntimeException(e);

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListTrie.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListTrie.java?rev=1235673&r1=1235672&r2=1235673&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListTrie.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/NodeListTrie.java
Wed Jan 25 08:22:27 2012
@@ -70,25 +70,13 @@ public class NodeListTrie implements Nod
             }
         }
         this.prefixLength = len;
-        String last = null;
-        NodeListSmall partList = new NodeListSmall();
         for (long i = 0;; i++) {
             String n = list.getName(i);
             if (n == null) {
                 break;
             }
-            String p = getPrefix(n, len);
-            if (last == null || p.equals(last)) {
-                partList.add(n, list.get(n));
-                last = p;
-            } else {
-                addChild(children.size(), last, partList);
-                partList = new NodeListSmall();
-                partList.add(n, list.get(n));
-                last = p;
-            }
+            add(n, list.get(n));
         }
-        addChild(children.size(), last, partList);
         this.size = size;
     }
 

Modified: jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
URL: http://svn.apache.org/viewvc/jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java?rev=1235673&r1=1235672&r2=1235673&view=diff
==============================================================================
--- jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
(original)
+++ jackrabbit/sandbox/microkernel/src/main/java/org/apache/jackrabbit/mk/mem/Revision.java
Wed Jan 25 08:22:27 2012
@@ -124,7 +124,7 @@ public class Revision implements Compara
         } else {
             commit.setProperty("diff", "[" + diff + "]");
         }
-        if (msg != null) {
+        if (msg != null && msg.length() > 0) {
             commit.setProperty("msg", JsopBuilder.encode(msg));
         }
         return head.setChild("commit", commit, id);



Mime
View raw message