]> source.dussan.org Git - jackcess.git/commitdiff
no need to sort entries, should already be sorted (but verify just to be paranoid)
authorJames Ahlborn <jtahlborn@yahoo.com>
Tue, 18 Mar 2008 20:25:32 +0000 (20:25 +0000)
committerJames Ahlborn <jtahlborn@yahoo.com>
Tue, 18 Mar 2008 20:25:32 +0000 (20:25 +0000)
git-svn-id: https://svn.code.sf.net/p/jackcess/code/jackcess/trunk@284 f203690c-595d-4dc9-a70b-905162fa7fd2

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

index 944866de5aa607957eb2d925f9a4b6b23ebffc43..5df3277fca06f7ad647abe979e0a6e0205136ae5 100644 (file)
@@ -41,7 +41,6 @@ import java.util.LinkedList;
 import java.util.List;
 import java.util.Map;
 import java.util.SortedSet;
-import java.util.TreeSet;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -396,9 +395,6 @@ public class Index implements Comparable<Index> {
   private void readIndexEntries()
     throws IOException
   {
-    // use sorted set initially to do the bulk of the sorting
-    SortedSet<Entry> tmpEntries = new TreeSet<Entry>();
-    
     ByteBuffer indexPage = getPageChannel().createPageBuffer();
 
     // find first leaf page
@@ -419,10 +415,11 @@ public class Index implements Comparable<Index> {
       }
     }
 
-    // read all leaf pages
+    // read all leaf pages.  since we read all the entries in sort order, we
+    // can insert them directly into the _entries list
     while(true) {
 
-      leafPageNumber = readLeafPage(indexPage, tmpEntries);
+      leafPageNumber = readLeafPage(indexPage, _entries);
       if(leafPageNumber != 0) {
         // FIXME we can't modify this index at this point in time
         _readOnly = true;
@@ -436,8 +433,15 @@ public class Index implements Comparable<Index> {
       }
     }
 
-    // dump all the entries (sorted) into the actual _entries list
-    _entries.addAll(tmpEntries);
+    // 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);
+      }
+    }
   }
 
   /**