mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-07 02:42:48 +03:00
Change pageInsertArray() and pageFreeArray() so that they use the CellArray
object and compute cell sizes as needed, resulting in smaller and faster code. FossilOrigin-Name: f7f41818119bb7bfbd1f1297d294b32f32769cd3
This commit is contained in:
12
manifest
12
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Improvements\sto\sthe\sway\sbalance_nonroot()\sconstructs\sthe\sb.apCell\sarray\sof\npointers\sto\scells.
|
C Change\spageInsertArray()\sand\spageFreeArray()\sso\sthat\sthey\suse\sthe\sCellArray\nobject\sand\scompute\scell\ssizes\sas\sneeded,\sresulting\sin\ssmaller\sand\sfaster\scode.
|
||||||
D 2015-06-23T14:49:42.852
|
D 2015-06-23T15:36:34.487
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025
|
F Makefile.in 1063c58075b7400d93326b0eb332b48a54f53025
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -192,7 +192,7 @@ F src/auth.c b56c78ebe40a2110fd361379f7e8162d23f92240
|
|||||||
F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3
|
F src/backup.c ff743689c4d6c5cb55ad42ed9d174b2b3e71f1e3
|
||||||
F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d
|
F src/bitvec.c 5eb7958c3bf65210211cbcfc44eff86d0ded7c9d
|
||||||
F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
|
F src/btmutex.c 45a968cc85afed9b5e6cf55bf1f42f8d18107f79
|
||||||
F src/btree.c 8d772673dc249aee6b6e65e4285291f7f2565ffd
|
F src/btree.c d3299e9237047e7aaf2812f394dda4889f2e3aa9
|
||||||
F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1
|
F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1
|
||||||
F src/btreeInt.h 6ece2dd9c8e2eac05f0a8ded8772a44e96486c65
|
F src/btreeInt.h 6ece2dd9c8e2eac05f0a8ded8772a44e96486c65
|
||||||
F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70
|
F src/build.c b3f15255d5b16e42dafeaa638fd4f8a47c94ed70
|
||||||
@@ -1286,7 +1286,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P a7be554f4b8534fc237fa4c6defc38fcd4049707
|
P ee44bb25b2a88e25ba2afe37cf03ba199692a3a0
|
||||||
R 4ad5f5185dfc9700d38a61349b40bf79
|
R 5ed6484269ac715a433769ddc5808d8c
|
||||||
U drh
|
U drh
|
||||||
Z 77f5541f0ad6043b85ab2e262249ce69
|
Z fb1540dd92109cdc5f0c16d0ac49412f
|
||||||
|
@@ -1 +1 @@
|
|||||||
ee44bb25b2a88e25ba2afe37cf03ba199692a3a0
|
f7f41818119bb7bfbd1f1297d294b32f32769cd3
|
49
src/btree.c
49
src/btree.c
@@ -6414,25 +6414,26 @@ static int pageInsertArray(
|
|||||||
u8 *pBegin, /* End of cell-pointer array */
|
u8 *pBegin, /* End of cell-pointer array */
|
||||||
u8 **ppData, /* IN/OUT: Page content -area pointer */
|
u8 **ppData, /* IN/OUT: Page content -area pointer */
|
||||||
u8 *pCellptr, /* Pointer to cell-pointer area */
|
u8 *pCellptr, /* Pointer to cell-pointer area */
|
||||||
|
int iFirst, /* Index of first cell to add */
|
||||||
int nCell, /* Number of cells to add to pPg */
|
int nCell, /* Number of cells to add to pPg */
|
||||||
u8 **apCell, /* Array of cells */
|
CellArray *pCArray /* Array of cells */
|
||||||
u16 *szCell /* Array of cell sizes */
|
|
||||||
){
|
){
|
||||||
int i;
|
int i;
|
||||||
u8 *aData = pPg->aData;
|
u8 *aData = pPg->aData;
|
||||||
u8 *pData = *ppData;
|
u8 *pData = *ppData;
|
||||||
const int bFreelist = aData[1] || aData[2];
|
const int bFreelist = aData[1] || aData[2];
|
||||||
|
int iEnd = iFirst + nCell;
|
||||||
assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
|
assert( CORRUPT_DB || pPg->hdrOffset==0 ); /* Never called on page 1 */
|
||||||
for(i=0; i<nCell; i++){
|
for(i=iFirst; i<iEnd; i++){
|
||||||
int sz = szCell[i];
|
int sz, rc;
|
||||||
int rc;
|
|
||||||
u8 *pSlot;
|
u8 *pSlot;
|
||||||
|
sz = cachedCellSize(pCArray, i);
|
||||||
if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
|
if( bFreelist==0 || (pSlot = pageFindSlot(pPg, sz, &rc, 0))==0 ){
|
||||||
pData -= sz;
|
pData -= sz;
|
||||||
if( pData<pBegin ) return 1;
|
if( pData<pBegin ) return 1;
|
||||||
pSlot = pData;
|
pSlot = pData;
|
||||||
}
|
}
|
||||||
memcpy(pSlot, apCell[i], sz);
|
memcpy(pSlot, pCArray->apCell[i], sz);
|
||||||
put2byte(pCellptr, (pSlot - aData));
|
put2byte(pCellptr, (pSlot - aData));
|
||||||
pCellptr += 2;
|
pCellptr += 2;
|
||||||
}
|
}
|
||||||
@@ -6451,22 +6452,27 @@ static int pageInsertArray(
|
|||||||
*/
|
*/
|
||||||
static int pageFreeArray(
|
static int pageFreeArray(
|
||||||
MemPage *pPg, /* Page to edit */
|
MemPage *pPg, /* Page to edit */
|
||||||
|
int iFirst, /* First cell to delete */
|
||||||
int nCell, /* Cells to delete */
|
int nCell, /* Cells to delete */
|
||||||
u8 **apCell, /* Array of cells */
|
CellArray *pCArray /* Array of cells */
|
||||||
u16 *szCell /* Array of cell sizes */
|
|
||||||
){
|
){
|
||||||
u8 * const aData = pPg->aData;
|
u8 * const aData = pPg->aData;
|
||||||
u8 * const pEnd = &aData[pPg->pBt->usableSize];
|
u8 * const pEnd = &aData[pPg->pBt->usableSize];
|
||||||
u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
|
u8 * const pStart = &aData[pPg->hdrOffset + 8 + pPg->childPtrSize];
|
||||||
int nRet = 0;
|
int nRet = 0;
|
||||||
int i;
|
int i;
|
||||||
|
int iEnd = iFirst + nCell;
|
||||||
u8 *pFree = 0;
|
u8 *pFree = 0;
|
||||||
int szFree = 0;
|
int szFree = 0;
|
||||||
|
|
||||||
for(i=0; i<nCell; i++){
|
for(i=iFirst; i<iEnd; i++){
|
||||||
u8 *pCell = apCell[i];
|
u8 *pCell = pCArray->apCell[i];
|
||||||
if( pCell>=pStart && pCell<pEnd ){
|
if( pCell>=pStart && pCell<pEnd ){
|
||||||
int sz = szCell[i];
|
int sz;
|
||||||
|
/* 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!=(pCell + sz) ){
|
||||||
if( pFree ){
|
if( pFree ){
|
||||||
assert( pFree>aData && (pFree - aData)<65536 );
|
assert( pFree>aData && (pFree - aData)<65536 );
|
||||||
@@ -6525,20 +6531,12 @@ static int editPage(
|
|||||||
|
|
||||||
/* Remove cells from the start and end of the page */
|
/* Remove cells from the start and end of the page */
|
||||||
if( iOld<iNew ){
|
if( iOld<iNew ){
|
||||||
int nShift;
|
int nShift = pageFreeArray(pPg, iOld, iNew-iOld, pCArray);
|
||||||
populateCellCache(pCArray, iOld, iNew-iOld);
|
|
||||||
nShift = pageFreeArray(
|
|
||||||
pPg, iNew-iOld, &pCArray->apCell[iOld], &pCArray->szCell[iOld]
|
|
||||||
);
|
|
||||||
memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
|
memmove(pPg->aCellIdx, &pPg->aCellIdx[nShift*2], nCell*2);
|
||||||
nCell -= nShift;
|
nCell -= nShift;
|
||||||
}
|
}
|
||||||
if( iNewEnd < iOldEnd ){
|
if( iNewEnd < iOldEnd ){
|
||||||
populateCellCache(pCArray, iNewEnd, iOldEnd-iNewEnd);
|
nCell -= pageFreeArray(pPg, iNewEnd, iOldEnd - iNewEnd, pCArray);
|
||||||
nCell -= pageFreeArray(
|
|
||||||
pPg, iOldEnd-iNewEnd,
|
|
||||||
&pCArray->apCell[iNewEnd], &pCArray->szCell[iNewEnd]
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pData = &aData[get2byteNotZero(&aData[hdr+5])];
|
pData = &aData[get2byteNotZero(&aData[hdr+5])];
|
||||||
@@ -6550,10 +6548,9 @@ static int editPage(
|
|||||||
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
|
assert( (iOld-iNew)<nNew || nCell==0 || CORRUPT_DB );
|
||||||
pCellptr = pPg->aCellIdx;
|
pCellptr = pPg->aCellIdx;
|
||||||
memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
|
memmove(&pCellptr[nAdd*2], pCellptr, nCell*2);
|
||||||
populateCellCache(pCArray, iNew, nAdd);
|
|
||||||
if( pageInsertArray(
|
if( pageInsertArray(
|
||||||
pPg, pBegin, &pData, pCellptr,
|
pPg, pBegin, &pData, pCellptr,
|
||||||
nAdd, &pCArray->apCell[iNew], &pCArray->szCell[iNew]
|
iNew, nAdd, pCArray
|
||||||
) ) goto editpage_fail;
|
) ) goto editpage_fail;
|
||||||
nCell += nAdd;
|
nCell += nAdd;
|
||||||
}
|
}
|
||||||
@@ -6565,20 +6562,18 @@ static int editPage(
|
|||||||
pCellptr = &pPg->aCellIdx[iCell * 2];
|
pCellptr = &pPg->aCellIdx[iCell * 2];
|
||||||
memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
|
memmove(&pCellptr[2], pCellptr, (nCell - iCell) * 2);
|
||||||
nCell++;
|
nCell++;
|
||||||
(void)cachedCellSize(pCArray, iCell + iNew);
|
|
||||||
if( pageInsertArray(
|
if( pageInsertArray(
|
||||||
pPg, pBegin, &pData, pCellptr,
|
pPg, pBegin, &pData, pCellptr,
|
||||||
1, &pCArray->apCell[iCell + iNew], &pCArray->szCell[iCell + iNew]
|
iCell+iNew, 1, pCArray
|
||||||
) ) goto editpage_fail;
|
) ) goto editpage_fail;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Append cells to the end of the page */
|
/* Append cells to the end of the page */
|
||||||
pCellptr = &pPg->aCellIdx[nCell*2];
|
pCellptr = &pPg->aCellIdx[nCell*2];
|
||||||
populateCellCache(pCArray, iNew+nCell, nNew-nCell);
|
|
||||||
if( pageInsertArray(
|
if( pageInsertArray(
|
||||||
pPg, pBegin, &pData, pCellptr,
|
pPg, pBegin, &pData, pCellptr,
|
||||||
nNew-nCell, &pCArray->apCell[iNew+nCell], &pCArray->szCell[iNew+nCell]
|
iNew+nCell, nNew-nCell, pCArray
|
||||||
) ) goto editpage_fail;
|
) ) goto editpage_fail;
|
||||||
|
|
||||||
pPg->nCell = nNew;
|
pPg->nCell = nNew;
|
||||||
|
Reference in New Issue
Block a user