]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Further size reduction and performance improvement in btree.c:allocateSpace().
authordrh <drh@noemail.net>
Wed, 20 Aug 2014 11:56:14 +0000 (11:56 +0000)
committerdrh <drh@noemail.net>
Wed, 20 Aug 2014 11:56:14 +0000 (11:56 +0000)
FossilOrigin-Name: 1cb1cd64930a6bc371143f7d2e77eb1c51498cb0

manifest
manifest.uuid
src/btree.c

index e9f109a9a7dfb45a57a3c9dac28af3e0d81f4e49..6883385671231f6511c83fc4ec10a4dbdf82b90b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Fix\sa\stypo\sin\sthe\sshowdb\susage\smessage.
-D 2014-08-20T10:42:16.102
+C Further\ssize\sreduction\sand\sperformance\simprovement\sin\sbtree.c:allocateSpace().
+D 2014-08-20T11:56:14.338
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -167,7 +167,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
 F src/backup.c a729e63cf5cd1829507cb7b8e89f99b95141bb53
 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb
 F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
-F src/btree.c c580f3fb3b3d1bf968e5c7e6a0ad48b7b0bd4366
+F src/btree.c 398ecbdb4a19230940955c10b4f35de958e9a05c
 F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a
 F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3
 F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b
@@ -1186,7 +1186,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 73637d12e31f5489efe37d8cf4ab50a1911d4c75
-R d268dbd0231a0e3f9784dd51ed74231a
-U dan
-Z b16b223d7974024b463d42100aaa47bd
+P 6c66beae97ba1799c908d3a33371dedbc7f3f58c
+R 28706ecaca72a1e3574ba7b8d51854c6
+U drh
+Z ca9532aeb7742cb91c75177cb9ee4fbc
index 45aa98f21f891374fced6b1f9210cce179059df8..d1bf93d7a5f4807f5efb5ac0a11a267ae14fd1cb 100644 (file)
@@ -1 +1 @@
-6c66beae97ba1799c908d3a33371dedbc7f3f58c
\ No newline at end of file
+1cb1cd64930a6bc371143f7d2e77eb1c51498cb0
\ No newline at end of file
index 2ed304d04b2ccc157a10ec51bf043b89174799c8..61848dcb838555fad972c845826b9e3ce1a2ea10 100644 (file)
@@ -1222,20 +1222,15 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
       return SQLITE_CORRUPT_BKPT;
     }
   }
+
+  /* If there is enough space between gap and top for one more cell pointer
+  ** array entry offset, and if the freelist is not empty, then search the
+  ** freelist looking for a free slot big enough to satisfy the request.
+  */
   testcase( gap+2==top );
   testcase( gap+1==top );
   testcase( gap==top );
-
-  if( data[hdr+7]>=60 ){
-    /* Always defragment highly fragmented pages */
-    rc = defragmentPage(pPage);
-    if( rc ) return rc;
-    top = get2byteNotZero(&data[hdr+5]);
-  }else if( gap+2<=top ){
-    /* Search the freelist looking for a free slot big enough to satisfy 
-    ** the request. The allocation is made from the first free slot in 
-    ** the list that is large enough to accommodate it.
-    */
+  if( gap+2<=top && (data[hdr+1] || data[hdr+2]) ){
     int pc, addr;
     for(addr=hdr+1; (pc = get2byte(&data[addr]))>0; addr=pc){
       int size;            /* Size of the free slot */
@@ -1248,6 +1243,7 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
         testcase( x==4 );
         testcase( x==3 );
         if( x<4 ){
+          if( data[hdr+7]>=60 ) goto defragment_page;
           /* Remove the slot from the free-list. Update the number of
           ** fragmented bytes within the page. */
           memcpy(&data[addr], &data[pc], 2);
@@ -1265,11 +1261,13 @@ static int allocateSpace(MemPage *pPage, int nByte, int *pIdx){
     }
   }
 
-  /* Check to make sure there is enough space in the gap to satisfy
-  ** the allocation.  If not, defragment.
+  /* The request could not be fulfilled using a freelist slot.  Check
+  ** to see if defragmentation is necessary.
   */
   testcase( gap+2+nByte==top );
   if( gap+2+nByte>top ){
+defragment_page:
+    assert( pPage->nCell>0 );
     rc = defragmentPage(pPage);
     if( rc ) return rc;
     top = get2byteNotZero(&data[hdr+5]);