]> source.dussan.org Git - jackcess.git/commitdiff
put entry validation inline with entry reading
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 15 Apr 2008 02:49:03 +0000 (02:49 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 15 Apr 2008 02:49:03 +0000 (02:49 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@326 f203690c-595d-4dc9-a70b-905162fa7fd2

src/java/com/healthmarketscience/jackcess/Index.java

index 9eb3ca1bcb8dd8431f0316946a0c0dc244fe8119..ec3629d5df0eb741cc88b31f24e9c73674db837e 100644 (file)
@@ -806,6 +806,7 @@ public abstract class Index implements Comparable<Index> {
       TempBufferHolder.newHolder(TempBufferHolder.Type.HARD, true,
                                  ByteOrder.BIG_ENDIAN);
 
+    Entry prevEntry = FIRST_ENTRY;
     for (int i = 0; i < entryMaskLength; i++) {
       byte entryMask = buffer.get(entryMaskPos + i);
       for (int j = 0; j < 8; j++) {
@@ -823,8 +824,14 @@ public abstract class Index implements Comparable<Index> {
             curEntryLen += entryPrefix.length;
           }
           totalEntrySize += curEntryLen;
+
+          Entry entry = newEntry(curEntryBuffer, curEntryLen, isLeaf);
+          if(prevEntry.compareTo(entry) >= 0) {
+            throw new IOException("Unexpected order in index entries, " +
+                                  prevEntry + " >= " + entry);
+          }
           
-          entries.add(newEntry(curEntryBuffer, curEntryLen, isLeaf));
+          entries.add(entry);
 
           if(entries.size() == 1) {
             if(entryPrefixLength > 0) {
@@ -836,19 +843,10 @@ public abstract class Index implements Comparable<Index> {
           }
 
           lastStart += length;
+          prevEntry = entry;
         }
       }
     }
-    
-    // check the entry order, just to be safe
-    for(int i = 0; i < (entries.size() - 1); ++i) {
-      Entry e1 = entries.get(i);
-      Entry e2 = entries.get(i + 1);
-      if(e1.compareTo(e2) > 0) {
-        throw new IOException("Unexpected order in index entries, " +
-                              e1 + " is greater than " + e2);
-      }
-    }
 
     dataPage.setEntryPrefix(entryPrefix != null ? entryPrefix : EMPTY_PREFIX);
     dataPage.setEntries(entries);