]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Modify the assemblePage() function in btree.c so that it runs slightly faster. (CVS...
authordanielk1977 <danielk1977@noemail.net>
Wed, 29 Apr 2009 17:49:59 +0000 (17:49 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Wed, 29 Apr 2009 17:49:59 +0000 (17:49 +0000)
FossilOrigin-Name: 7ec42e989f1d4abdc6d52f8feebf51985f36b2bd

manifest
manifest.uuid
src/btree.c

index 3b69d29f577982571aab2143d51d7655a2cc849c..8c93625b93083190c6df662d64ce4edb864160c6 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Update\sthe\sdocumentation\son\sthe\ssqlite3_changes()\sand\ssqlite3_total_changes()\nfunctions.\s(CVS\s6568)
-D 2009-04-29T14:33:44
+C Modify\sthe\sassemblePage()\sfunction\sin\sbtree.c\sso\sthat\sit\sruns\sslightly\sfaster.\s(CVS\s6569)
+D 2009-04-29T17:49:59
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
 F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d
 F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
-F src/btree.c d3e38cf751251096c2d2017ff9f2375e29bf0f99
+F src/btree.c 57b2aeac717e9cfa959b8b57d11d3d3e8093e162
 F src/btree.h 99fcc7e8c4a1e35afe271bcb38de1a698dfc904e
 F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
 F src/build.c dca0ad77c88cb00f6a11cc080a4f3285672cfa37
@@ -725,7 +725,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P 9664e2b6c69271a7ca55af7812a186773a7c6592
-R 8444b35afee909cdcb2c2ac18b099c09
-U drh
-Z b5d9513f3dd8602eb18f6166440d0146
+P 58c7bdb21c719bf06713ff8ffa7ee51cf1973712
+R 9145a583971405864bb9bd62ca2de2c1
+U danielk1977
+Z d09c5a2c4f4e5bd4d6f77225050209bb
index 163416c15b20f3dd040f51cc1da65554b22c1480..6b956da55e3dd587410c913e3573f8bd9cb97296 100644 (file)
@@ -1 +1 @@
-58c7bdb21c719bf06713ff8ffa7ee51cf1973712
\ No newline at end of file
+7ec42e989f1d4abdc6d52f8feebf51985f36b2bd
\ No newline at end of file
index 7ff7c806c427665e585bc5a95e0e02ad6b027793..6fe22c163b61be6ec9a56655f61d20379cfd073e 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.598 2009/04/29 11:31:47 danielk1977 Exp $
+** $Id: btree.c,v 1.599 2009/04/29 17:49:59 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** See the header comment on "btreeInt.h" for additional information.
@@ -961,13 +961,13 @@ static int allocateSpace(MemPage *pPage, int nByte){
       if( size>=nByte ){
         int x = size - nByte;
         if( x<4 ){
-         /* Remove the slot from the free-list. Update the number of
-         ** fragmented bytes within the page. */
+          /* Remove the slot from the free-list. Update the number of
+          ** fragmented bytes within the page. */
           memcpy(&data[addr], &data[pc], 2);
           data[hdr+7] = (u8)(nFrag + x);
         }else{
-         /* The slot remains on the free-list. Reduce its size to account
-         ** for the portion used by the new allocation. */
+          /* The slot remains on the free-list. Reduce its size to account
+          ** for the portion used by the new allocation. */
           put2byte(&data[pc+2], x);
         }
         return pc + x;
@@ -3912,7 +3912,6 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
       assert( pCur->eState==CURSOR_VALID );
       *pRes = 0;
       rc = moveToRightmost(pCur);
-      getCellInfo(pCur);
       pCur->atLast = rc==SQLITE_OK ?1:0;
     }
   }
@@ -5044,39 +5043,32 @@ static void assemblePage(
   u16 *aSize        /* Sizes of the cells */
 ){
   int i;            /* Loop counter */
-  int totalSize;    /* Total size of all cells */
-  int hdr;          /* Index of page header */
-  int cellptr;      /* Address of next cell pointer */
+  u8 *pCellptr;     /* Address of next cell pointer */
   int cellbody;     /* Address of next cell body */
-  u8 *data;         /* Data for the page */
+  u8 * const data = pPage->aData;             /* Pointer to data for pPage */
+  const int hdr = pPage->hdrOffset;           /* Offset of header on pPage */
+  const int nUsable = pPage->pBt->usableSize; /* Usable size of page */
 
   assert( pPage->nOverflow==0 );
   assert( sqlite3_mutex_held(pPage->pBt->mutex) );
   assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 );
-  totalSize = 0;
-  for(i=0; i<nCell; i++){
-    totalSize += aSize[i];
-  }
-  assert( totalSize+2*nCell<=pPage->nFree );
-  assert( pPage->nCell==0 );
   assert( sqlite3PagerIswriteable(pPage->pDbPage) );
-  cellptr = pPage->cellOffset;
-  data = pPage->aData;
-  hdr = pPage->hdrOffset;
-  put2byte(&data[hdr+3], nCell);
-  if( nCell ){
-    cellbody = allocateSpace(pPage, totalSize);
-    assert( cellbody>0 );
-    assert( pPage->nFree >= 2*nCell );
-    pPage->nFree -= 2*nCell;
-    for(i=0; i<nCell; i++){
-      put2byte(&data[cellptr], cellbody);
-      memcpy(&data[cellbody], apCell[i], aSize[i]);
-      cellptr += 2;
-      cellbody += aSize[i];
-    }
-    assert( cellbody==pPage->pBt->usableSize );
+
+  /* Check that the page has just been zeroed by zeroPage() */
+  assert( pPage->nCell==0 );
+  assert( get2byte(&data[hdr+5])==nUsable );
+
+  pCellptr = &data[pPage->cellOffset + nCell*2];
+  cellbody = nUsable;
+  for(i=nCell-1; i>=0; i--){
+    pCellptr -= 2;
+    cellbody -= aSize[i];
+    put2byte(pCellptr, cellbody);
+    memcpy(&data[cellbody], apCell[i], aSize[i]);
   }
+  put2byte(&data[hdr+3], nCell);
+  put2byte(&data[hdr+5], cellbody);
+  pPage->nFree -= (nCell*2 + nUsable - cellbody);
   pPage->nCell = (u16)nCell;
 }