aboutsummaryrefslogtreecommitdiff
path: root/src/btree.c
diff options
context:
space:
mode:
authordrh <>2024-05-27 15:13:49 +0000
committerdrh <>2024-05-27 15:13:49 +0000
commit09d8e696dcb553c3733f012b964d195cfaa1953c (patch)
tree36f28bcb340f8866705bcfe20cafe2325bff4e28 /src/btree.c
parent20c118faec2e41089dc72ac974e21c096c2654bb (diff)
downloadsqlite-09d8e696dcb553c3733f012b964d195cfaa1953c.tar.gz
sqlite-09d8e696dcb553c3733f012b964d195cfaa1953c.zip
Very small performance increase and size reduction by removing unnecessary
ALWAYS() macros from the btree balance logic and replacing them with special initialization of CellArray and some assert()s. FossilOrigin-Name: 32b79041d9b6858e4ffade5841898619c7d25d20c4638bf85447a2ca9cc4a3d3
Diffstat (limited to 'src/btree.c')
-rw-r--r--src/btree.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/btree.c b/src/btree.c
index aa41ec3ba..1c47ace50 100644
--- a/src/btree.c
+++ b/src/btree.c
@@ -7567,8 +7567,8 @@ static int rebuildPage(
if( j>(u32)usableSize ){ j = 0; }
memcpy(&pTmp[j], &aData[j], usableSize - j);
- for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i; k++){}
- assert( k<NB*2 );
+ assert( pCArray->ixNx[NB*2-1]>i );
+ for(k=0; pCArray->ixNx[k]<=i; k++){}
pSrcEnd = pCArray->apEnd[k];
pData = pEnd;
@@ -7651,8 +7651,8 @@ static int pageInsertArray(
u8 *pEnd; /* Maximum extent of cell data */
assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
if( iEnd<=iFirst ) return 0;
- for(k=0; ALWAYS(k<NB*2) && pCArray->ixNx[k]<=i ; k++){}
- assert( k<NB*2 );
+ assert( pCArray->ixNx[NB*2-1]>i );
+ for(k=0; pCArray->ixNx[k]<=i ; k++){}
pEnd = pCArray->apEnd[k];
while( 1 /*Exit by break*/ ){
int sz, rc;
@@ -8172,7 +8172,9 @@ static int balance_nonroot(
CellArray b; /* Parsed information on cells being balanced */
memset(abDone, 0, sizeof(abDone));
- memset(&b, 0, sizeof(b));
+ assert( sizeof(b) - sizeof(b.ixNx) == offsetof(CellArray,ixNx) );
+ memset(&b, 0, sizeof(b)-sizeof(b.ixNx));
+ b.ixNx[NB*2-1] = 0x7fffffff;
pBt = pParent->pBt;
assert( sqlite3_mutex_held(pBt->mutex) );
assert( sqlite3PagerIswriteable(pParent->pDbPage) );
@@ -8763,8 +8765,8 @@ static int balance_nonroot(
iOvflSpace += sz;
assert( sz<=pBt->maxLocal+23 );
assert( iOvflSpace <= (int)pBt->pageSize );
- for(k=0; ALWAYS(k<NB*2) && b.ixNx[k]<=j; k++){}
- assert( k<NB*2 );
+ assert( b.ixNx[NB*2-1]>j );
+ for(k=0; b.ixNx[k]<=j; k++){}
pSrcEnd = b.apEnd[k];
if( SQLITE_OVERFLOW(pSrcEnd, pCell, pCell+sz) ){
rc = SQLITE_CORRUPT_BKPT;