1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-05 15:55:57 +03:00

Increase the size of the cache of free blocks inside of pageFreeArray() to

reduce the number of calls to freeSpace().

FossilOrigin-Name: 27c59f1ea789f3ff245f23e79ded5cd71c48e3a51ffbb8c220b51101a4e69fd7
This commit is contained in:
drh
2023-04-06 20:14:10 +00:00
parent 82412051db
commit 50dc8d9720
3 changed files with 37 additions and 27 deletions

View File

@@ -7496,42 +7496,49 @@ static int pageFreeArray(
u8 * const pEnd = &aData[pPg->pBt->usableSize];
u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
int nRet = 0;
int i;
int i, j;
int iEnd = iFirst + nCell;
u8 *pFree = 0; /* \__ Parameters for pending call to */
int szFree = 0; /* / freeSpace() */
int nFree = 0;
int aOfst[10];
int aAfter[10];
for(i=iFirst; i<iEnd; i++){
u8 *pCell = pCArray->apCell[i];
if( SQLITE_WITHIN(pCell, pStart, pEnd) ){
int sz;
int iAfter;
int iOfst;
/* No need to use cachedCellSize() here. The sizes of all cells that
** are to be freed have already been computing while deciding which
** cells need freeing */
sz = pCArray->szCell[i]; assert( sz>0 );
if( pFree!=(pCell + sz) ){
if( pFree ){
assert( pFree>aData && (pFree - aData)<65536 );
freeSpace(pPg, (u16)(pFree - aData), szFree);
iOfst = (u16)(pCell - aData);
iAfter = iOfst+sz;
for(j=0; j<nFree; j++){
if( aOfst[j]==iAfter ){
aOfst[j] = iOfst;
break;
}else if( aAfter[j]==iOfst ){
aAfter[j] = iAfter;
break;
}
pFree = pCell;
szFree = sz;
if( pFree+sz>pEnd ){
return 0;
}
if( j>=nFree ){
if( nFree>=sizeof(aOfst)/sizeof(aOfst[0]) ){
for(j=0; j<nFree; j++){
freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]);
}
nFree = 0;
}
}else{
/* The current cell is adjacent to and before the pFree cell.
** Combine the two regions into one to reduce the number of calls
** to freeSpace(). */
pFree = pCell;
szFree += sz;
aOfst[nFree] = iOfst;
aAfter[nFree] = iAfter;
nFree++;
}
nRet++;
}
}
if( pFree ){
assert( pFree>aData && (pFree - aData)<65536 );
freeSpace(pPg, (u16)(pFree - aData), szFree);
for(j=0; j<nFree; j++){
freeSpace(pPg, aOfst[j], aAfter[j]-aOfst[j]);
}
return nRet;
}