mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Reduce the amount of memcpy() required by defragmentPage().
FossilOrigin-Name: 3edab9957cc7bb90b52fd40b02613c2cb03fc166
This commit is contained in:
25
src/btree.c
25
src/btree.c
@@ -1151,6 +1151,7 @@ static int defragmentPage(MemPage *pPage){
|
||||
int nCell; /* Number of cells on the page */
|
||||
unsigned char *data; /* The page data */
|
||||
unsigned char *temp; /* Temp area for cell content */
|
||||
unsigned char *src; /* Source of content */
|
||||
int iCellFirst; /* First allowable cell index */
|
||||
int iCellLast; /* Last possible cell index */
|
||||
|
||||
@@ -1160,15 +1161,13 @@ static int defragmentPage(MemPage *pPage){
|
||||
assert( pPage->pBt->usableSize <= SQLITE_MAX_PAGE_SIZE );
|
||||
assert( pPage->nOverflow==0 );
|
||||
assert( sqlite3_mutex_held(pPage->pBt->mutex) );
|
||||
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
|
||||
data = pPage->aData;
|
||||
temp = 0;
|
||||
src = data = pPage->aData;
|
||||
hdr = pPage->hdrOffset;
|
||||
cellOffset = pPage->cellOffset;
|
||||
nCell = pPage->nCell;
|
||||
assert( nCell==get2byte(&data[hdr+3]) );
|
||||
usableSize = pPage->pBt->usableSize;
|
||||
cbrk = get2byte(&data[hdr+5]);
|
||||
memcpy(&temp[cbrk], &data[cbrk], usableSize - cbrk);
|
||||
cbrk = usableSize;
|
||||
iCellFirst = cellOffset + 2*nCell;
|
||||
iCellLast = usableSize - 4;
|
||||
@@ -1187,7 +1186,7 @@ static int defragmentPage(MemPage *pPage){
|
||||
}
|
||||
#endif
|
||||
assert( pc>=iCellFirst && pc<=iCellLast );
|
||||
size = cellSizePtr(pPage, &temp[pc]);
|
||||
size = cellSizePtr(pPage, &src[pc]);
|
||||
cbrk -= size;
|
||||
#if defined(SQLITE_ENABLE_OVERSIZE_CELL_CHECK)
|
||||
if( cbrk<iCellFirst ){
|
||||
@@ -1201,8 +1200,16 @@ static int defragmentPage(MemPage *pPage){
|
||||
assert( cbrk+size<=usableSize && cbrk>=iCellFirst );
|
||||
testcase( cbrk+size==usableSize );
|
||||
testcase( pc+size==usableSize );
|
||||
memcpy(&data[cbrk], &temp[pc], size);
|
||||
put2byte(pAddr, cbrk);
|
||||
if( temp==0 ){
|
||||
int x;
|
||||
if( cbrk==pc ) continue;
|
||||
temp = sqlite3PagerTempSpace(pPage->pBt->pPager);
|
||||
x = get2byte(&data[hdr+5]);
|
||||
memcpy(&temp[x], &data[x], (cbrk+size) - x);
|
||||
src = temp;
|
||||
}
|
||||
memcpy(&data[cbrk], &src[pc], size);
|
||||
}
|
||||
assert( cbrk>=iCellFirst );
|
||||
put2byte(&data[hdr+5], cbrk);
|
||||
@@ -5955,13 +5962,13 @@ static void assemblePage(
|
||||
assert( pPage->nCell==0 );
|
||||
assert( get2byteNotZero(&data[hdr+5])==nUsable );
|
||||
|
||||
pCellptr = &pPage->aCellIdx[nCell*2];
|
||||
pCellptr = pPage->aCellIdx;
|
||||
cellbody = nUsable;
|
||||
for(i=nCell-1; i>=0; i--){
|
||||
for(i=0; i<nCell; i++){
|
||||
u16 sz = aSize[i];
|
||||
pCellptr -= 2;
|
||||
cellbody -= sz;
|
||||
put2byte(pCellptr, cellbody);
|
||||
pCellptr += 2;
|
||||
memcpy(&data[cellbody], apCell[i], sz);
|
||||
}
|
||||
put2byte(&data[hdr+3], nCell);
|
||||
|
Reference in New Issue
Block a user