]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Have each {quote: BtShared} structure hang on to a buffer of just under page-size...
authordanielk1977 <danielk1977@noemail.net>
Tue, 25 Mar 2008 14:24:56 +0000 (14:24 +0000)
committerdanielk1977 <danielk1977@noemail.net>
Tue, 25 Mar 2008 14:24:56 +0000 (14:24 +0000)
FossilOrigin-Name: fe1bc0f3b7cd87cd65f7d03b91095b59788a6f8d

manifest
manifest.uuid
src/btree.c
src/btreeInt.h

index c904b91515d8e2e811bb85031770b3efa34e2e75..153758578163ead299206982e238a014e470a40e 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sfor\smemory\sleak\sin\smalloc3.test.\s(CVS\s4913)
-D 2008-03-25T09:56:45
+C Have\seach\s{quote:\sBtShared}\sstructure\shang\son\sto\sa\sbuffer\sof\sjust\sunder\spage-size\sbytes\sfor\stemporary\suse.\sThis\sreduces\sthe\snumber\sof\scalls\sto\smalloc().\s(CVS\s4914)
+D 2008-03-25T14:24:57
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in cf434ce8ca902e69126ae0f94fc9f7dc7428a5fa
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -86,9 +86,9 @@ F src/attach.c bdc75e759ca25a16f4dc7fbdbc6d37ad2561bb24
 F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
 F src/bitvec.c 49817d442e51e4123585f3cf3c2afc293a3c91e2
 F src/btmutex.c 483ced3c52205b04b97df69161fadbf87f4f1ea2
-F src/btree.c 0a170b7bb69035f6e5c4d722e907b908c5480e83
+F src/btree.c 366f5f66ebb3dfdc8513242d4aecbfb402dcc0a9
 F src/btree.h e02869e1e7753ad5b3c7cb7852e952c95c2e609a
-F src/btreeInt.h c2deca3e778e2a1e6196343b8087a868f4faa19a
+F src/btreeInt.h d232be68a7ab2a24376dc6332a869e717551b0bd
 F src/build.c d0715b3454b140cb405412e3029ec7c0fb434efd
 F src/callback.c 77b302b0d41468dcda78c70e706e5b84577f0fa0
 F src/complete.c 4cf68fd75d60257524cbe74f87351b9848399131
@@ -617,7 +617,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 047153648155654b0cd70b811935209d2e21776c
-R fe7778c82934f6b01597127050469d93
+P ef0e40e814b3d3a00721f8ca39bac0db1be24347
+R d58ce8f374758d218509d77eae1fa411
 U danielk1977
-Z cbb9339bf69751e7040fab28fe7c6c53
+Z 6b876eb9851a975cdfed8252be002c4a
index 994285ef9882f8618e9b5728c4f60d3ba2d58bb0..95e12400e5cd5f194b1b6c33adbb8b637425078e 100644 (file)
@@ -1 +1 @@
-ef0e40e814b3d3a00721f8ca39bac0db1be24347
\ No newline at end of file
+fe1bc0f3b7cd87cd65f7d03b91095b59788a6f8d
\ No newline at end of file
index 8353963010ec186a0e87c7a415f44981d2ff7e8c..27450094f324e9f62baa0b7b2777df57be5ac7ff 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.445 2008/03/25 09:56:45 danielk1977 Exp $
+** $Id: btree.c,v 1.446 2008/03/25 14:24:57 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** See the header comment on "btreeInt.h" for additional information.
@@ -1440,6 +1440,7 @@ int sqlite3BtreeClose(Btree *p){
       pBt->xFreeSchema(pBt->pSchema);
     }
     sqlite3_free(pBt->pSchema);
+    sqlite3_free(pBt->pTmpSpace);
     sqlite3_free(pBt);
   }
 
@@ -1544,6 +1545,8 @@ int sqlite3BtreeSetPageSize(Btree *p, int pageSize, int nReserve){
     assert( (pageSize & 7)==0 );
     assert( !pBt->pPage1 && !pBt->pCursor );
     pBt->pageSize = pageSize;
+    sqlite3_free(pBt->pTmpSpace);
+    pBt->pTmpSpace = 0;
     rc = sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
   }
   pBt->usableSize = pBt->pageSize - nReserve;
@@ -1678,6 +1681,8 @@ static int lockBtree(BtShared *pBt){
       releasePage(pPage1);
       pBt->usableSize = usableSize;
       pBt->pageSize = pageSize;
+      sqlite3_free(pBt->pTmpSpace);
+      pBt->pTmpSpace = 0;
       sqlite3PagerSetPagesize(pBt->pPager, &pBt->pageSize);
       return SQLITE_OK;
     }
@@ -5558,6 +5563,16 @@ static int checkReadLocks(Btree *pBtree, Pgno pgnoRoot, BtCursor *pExclude){
   return SQLITE_OK;
 }
 
+/*
+** Make sure pBt->pTmpSpace points to an allocation of 
+** MX_CELL_SIZE(pBt) bytes.
+*/
+static void allocateTempSpace(BtShared *pBt){
+  if( !pBt->pTmpSpace ){
+    pBt->pTmpSpace = sqlite3_malloc(MX_CELL_SIZE(pBt));
+  }
+}
+
 /*
 ** Insert a new record into the BTree.  The key is given by (pKey,nKey)
 ** and the data is given by (pData,nData).  The cursor is used only to
@@ -5616,7 +5631,8 @@ int sqlite3BtreeInsert(
           pCur->pgnoRoot, nKey, nData, pPage->pgno,
           loc==0 ? "overwrite" : "new entry"));
   assert( pPage->isInit );
-  newCell = sqlite3_malloc( MX_CELL_SIZE(pBt) );
+  allocateTempSpace(pBt);
+  newCell = pBt->pTmpSpace;
   if( newCell==0 ) return SQLITE_NOMEM;
   rc = fillInCell(pPage, newCell, pKey, nKey, pData, nData, nZero, &szNew);
   if( rc ) goto end_insert;
@@ -5653,7 +5669,6 @@ int sqlite3BtreeInsert(
     moveToRoot(pCur);
   }
 end_insert:
-  sqlite3_free(newCell);
   return rc;
 }
 
@@ -5742,7 +5757,8 @@ int sqlite3BtreeDelete(BtCursor *pCur){
       pNext = findCell(leafCur.pPage, leafCur.idx);
       szNext = cellSizePtr(leafCur.pPage, pNext);
       assert( MX_CELL_SIZE(pBt)>=szNext+4 );
-      tempCell = sqlite3_malloc( MX_CELL_SIZE(pBt) );
+      allocateTempSpace(pBt);
+      tempCell = pBt->pTmpSpace;
       if( tempCell==0 ){
         rc = SQLITE_NOMEM;
       }
@@ -5758,7 +5774,6 @@ int sqlite3BtreeDelete(BtCursor *pCur){
         rc = balance(leafCur.pPage, 0);
       }
     }
-    sqlite3_free(tempCell);
     sqlite3BtreeReleaseTempCursor(&leafCur);
   }else{
     TRACE(("DELETE: table=%d delete from leaf %d\n",
index b4f9854b92a9d1eb6c7f1a2051277d881372c118..6045753caf6a2dec3ee2f61a0a7d206a077d6cdc 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btreeInt.h,v 1.18 2008/03/25 00:22:21 drh Exp $
+** $Id: btreeInt.h,v 1.19 2008/03/25 14:24:57 danielk1977 Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -398,6 +398,7 @@ struct BtShared {
   BtLock *pLock;        /* List of locks held on this shared-btree struct */
   Btree *pExclusive;    /* Btree with an EXCLUSIVE lock on the whole db */
 #endif
+  u8 *pTmpSpace;        /* BtShared.pageSize bytes of space for tmp use */
 };
 
 /*