1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Modify the assemblePage() function in btree.c so that it runs slightly faster. (CVS 6569)

FossilOrigin-Name: 7ec42e989f1d4abdc6d52f8feebf51985f36b2bd
This commit is contained in:
danielk1977
2009-04-29 17:49:59 +00:00
parent d9c20d71c2
commit fad9194453
3 changed files with 32 additions and 40 deletions

View File

@@ -1,5 +1,5 @@
C Update\sthe\sdocumentation\son\sthe\ssqlite3_changes()\sand\ssqlite3_total_changes()\nfunctions.\s(CVS\s6568) C Modify\sthe\sassemblePage()\sfunction\sin\sbtree.c\sso\sthat\sit\sruns\sslightly\sfaster.\s(CVS\s6569)
D 2009-04-29T14:33:44 D 2009-04-29T17:49:59
F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
F Makefile.in 583e87706abc3026960ed759aff6371faf84c211 F Makefile.in 583e87706abc3026960ed759aff6371faf84c211
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -106,7 +106,7 @@ F src/auth.c c8b2ab5c8bad4bd90ed7c294694f48269162c627
F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d F src/backup.c 0082d0e5a63f04e88faee0dff0a7d63d3e92a78d
F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d F src/bitvec.c ef370407e03440b0852d05024fb016b14a471d3d
F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c F src/btmutex.c 9b899c0d8df3bd68f527b0afe03088321b696d3c
F src/btree.c d3e38cf751251096c2d2017ff9f2375e29bf0f99 F src/btree.c 57b2aeac717e9cfa959b8b57d11d3d3e8093e162
F src/btree.h 99fcc7e8c4a1e35afe271bcb38de1a698dfc904e F src/btree.h 99fcc7e8c4a1e35afe271bcb38de1a698dfc904e
F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5 F src/btreeInt.h df64030d632f8c8ac217ed52e8b6b3eacacb33a5
F src/build.c dca0ad77c88cb00f6a11cc080a4f3285672cfa37 F src/build.c dca0ad77c88cb00f6a11cc080a4f3285672cfa37
@@ -725,7 +725,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
P 9664e2b6c69271a7ca55af7812a186773a7c6592 P 58c7bdb21c719bf06713ff8ffa7ee51cf1973712
R 8444b35afee909cdcb2c2ac18b099c09 R 9145a583971405864bb9bd62ca2de2c1
U drh U danielk1977
Z b5d9513f3dd8602eb18f6166440d0146 Z d09c5a2c4f4e5bd4d6f77225050209bb

View File

@@ -1 +1 @@
58c7bdb21c719bf06713ff8ffa7ee51cf1973712 7ec42e989f1d4abdc6d52f8feebf51985f36b2bd

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give. ** 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. ** This file implements a external (disk-based) database using BTrees.
** See the header comment on "btreeInt.h" for additional information. ** See the header comment on "btreeInt.h" for additional information.
@@ -961,13 +961,13 @@ static int allocateSpace(MemPage *pPage, int nByte){
if( size>=nByte ){ if( size>=nByte ){
int x = size - nByte; int x = size - nByte;
if( x<4 ){ if( x<4 ){
/* Remove the slot from the free-list. Update the number of /* Remove the slot from the free-list. Update the number of
** fragmented bytes within the page. */ ** fragmented bytes within the page. */
memcpy(&data[addr], &data[pc], 2); memcpy(&data[addr], &data[pc], 2);
data[hdr+7] = (u8)(nFrag + x); data[hdr+7] = (u8)(nFrag + x);
}else{ }else{
/* The slot remains on the free-list. Reduce its size to account /* The slot remains on the free-list. Reduce its size to account
** for the portion used by the new allocation. */ ** for the portion used by the new allocation. */
put2byte(&data[pc+2], x); put2byte(&data[pc+2], x);
} }
return pc + x; return pc + x;
@@ -3912,7 +3912,6 @@ int sqlite3BtreeLast(BtCursor *pCur, int *pRes){
assert( pCur->eState==CURSOR_VALID ); assert( pCur->eState==CURSOR_VALID );
*pRes = 0; *pRes = 0;
rc = moveToRightmost(pCur); rc = moveToRightmost(pCur);
getCellInfo(pCur);
pCur->atLast = rc==SQLITE_OK ?1:0; pCur->atLast = rc==SQLITE_OK ?1:0;
} }
} }
@@ -5044,39 +5043,32 @@ static void assemblePage(
u16 *aSize /* Sizes of the cells */ u16 *aSize /* Sizes of the cells */
){ ){
int i; /* Loop counter */ int i; /* Loop counter */
int totalSize; /* Total size of all cells */ u8 *pCellptr; /* Address of next cell pointer */
int hdr; /* Index of page header */
int cellptr; /* Address of next cell pointer */
int cellbody; /* Address of next cell body */ 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( pPage->nOverflow==0 );
assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( sqlite3_mutex_held(pPage->pBt->mutex) );
assert( nCell>=0 && nCell<=MX_CELL(pPage->pBt) && MX_CELL(pPage->pBt)<=5460 ); 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) ); assert( sqlite3PagerIswriteable(pPage->pDbPage) );
cellptr = pPage->cellOffset;
data = pPage->aData; /* Check that the page has just been zeroed by zeroPage() */
hdr = pPage->hdrOffset; assert( pPage->nCell==0 );
put2byte(&data[hdr+3], nCell); assert( get2byte(&data[hdr+5])==nUsable );
if( nCell ){
cellbody = allocateSpace(pPage, totalSize); pCellptr = &data[pPage->cellOffset + nCell*2];
assert( cellbody>0 ); cellbody = nUsable;
assert( pPage->nFree >= 2*nCell ); for(i=nCell-1; i>=0; i--){
pPage->nFree -= 2*nCell; pCellptr -= 2;
for(i=0; i<nCell; i++){ cellbody -= aSize[i];
put2byte(&data[cellptr], cellbody); put2byte(pCellptr, cellbody);
memcpy(&data[cellbody], apCell[i], aSize[i]); memcpy(&data[cellbody], apCell[i], aSize[i]);
cellptr += 2;
cellbody += aSize[i];
}
assert( cellbody==pPage->pBt->usableSize );
} }
put2byte(&data[hdr+3], nCell);
put2byte(&data[hdr+5], cellbody);
pPage->nFree -= (nCell*2 + nUsable - cellbody);
pPage->nCell = (u16)nCell; pPage->nCell = (u16)nCell;
} }