jackrabbit-oak-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ju...@apache.org
Subject svn commit: r1528519 - in /jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment: MapLeaf.java MapRecord.java
Date Wed, 02 Oct 2013 15:27:59 GMT
Author: jukka
Date: Wed Oct  2 15:27:58 2013
New Revision: 1528519

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

Some further MapLeaf simplifications

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

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java?rev=1528519&r1=1528518&r2=1528519&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapLeaf.java
Wed Oct  2 15:27:58 2013
@@ -37,21 +37,23 @@ class MapLeaf extends MapRecord {
 
     @Override
     RecordId getEntry(String key) {
-        checkNotNull(key);
+        if (size == 0) {
+            return null;
+        }
 
-        if (size > 0) {
-            int hash = key.hashCode();
-            Segment segment = getSegment();
-
-            int index = 0;
-            while (index < size && getHash(segment, index) < hash) {
-                index++;
-            }
-            while (index < size && getHash(segment, index) == hash) {
-                if (key.equals(getKey(segment, index))) {
-                    return getValue(segment, index);
-                }
-                index++;
+        Segment segment = getSegment();
+        int hash = checkNotNull(key).hashCode();
+
+        for (int i = 0; i < size; i++) {
+            int d = Integer.compare(segment.readInt(getOffset(4 + i * 4)), hash);
+            if (d == 0) {
+                RecordId id = segment.readRecordId(getOffset(4 + size * 4, i));
+                d = segment.readString(id).compareTo(key);
+            }
+            if (d == 0) {
+                return segment.readRecordId(getOffset(4 + size * 4, size + i));
+            } else if (d > 0) {
+                return null;
             }
         }
 
@@ -156,21 +158,6 @@ class MapLeaf extends MapRecord {
         return true;
     }
 
-    @Override
-    public boolean compareAgainstEmptyMap(MapDiff diff) {
-        Segment segment = getSegment();
-
-        for (int i = 0; i < size; i++) {
-            RecordId key = segment.readRecordId(getOffset(4 + size * 4, i));
-            RecordId value = segment.readRecordId(getOffset(4 + size * 4, size + i));
-            if (!diff.entryAdded(segment.readString(key), value)) {
-                return false;
-            }
-        }
-
-        return true;
-    }
-
     //-----------------------------------------------------------< private >--
 
     private int getHash(Segment segment, int index) {

Modified: jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
URL: http://svn.apache.org/viewvc/jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java?rev=1528519&r1=1528518&r2=1528519&view=diff
==============================================================================
--- jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
(original)
+++ jackrabbit/oak/trunk/oak-core/src/main/java/org/apache/jackrabbit/oak/plugins/segment/MapRecord.java
Wed Oct  2 15:27:58 2013
@@ -84,7 +84,14 @@ abstract class MapRecord extends Record 
 
     abstract Iterable<MapEntry> getEntries();
 
-    abstract boolean compareAgainstEmptyMap(MapDiff diff);
+    boolean compareAgainstEmptyMap(MapDiff diff) {
+        for (MapEntry entry : getEntries()) {
+            if (!diff.entryAdded(entry.getName(), entry.getValue())) {
+                return false;
+            }
+        }
+        return true;
+    }
 
     interface MapDiff {
         boolean entryAdded(String key, RecordId after);



Mime
View raw message