diff options
author | drh <drh@noemail.net> | 2015-06-19 20:31:02 +0000 |
---|---|---|
committer | drh <drh@noemail.net> | 2015-06-19 20:31:02 +0000 |
commit | b11b0efde6d9722cee4f810b3b6a2eed92599be8 (patch) | |
tree | a163d381ade0b57216a5d66ba961c0bce1460aba /src | |
parent | 5fa605142fc687e2fb636981b475a33a29fd178a (diff) | |
parent | eeab2c63a95af9a15f007edd90b37dab286097e4 (diff) | |
download | sqlite-b11b0efde6d9722cee4f810b3b6a2eed92599be8.tar.gz sqlite-b11b0efde6d9722cee4f810b3b6a2eed92599be8.zip |
Performance improvements in btreeParseCell() by inlining the varint decoder.
FossilOrigin-Name: 172a864d14fd9f0e3e97d2a13b22222ae0fedd39
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 47 |
1 files changed, 43 insertions, 4 deletions
diff --git a/src/btree.c b/src/btree.c index bc3c13437..e64139b80 100644 --- a/src/btree.c +++ b/src/btree.c @@ -1054,6 +1054,7 @@ static void btreeParseCellPtr( ){ u8 *pIter; /* For scanning through pCell */ u32 nPayload; /* Number of bytes of cell payload */ + u64 iKey; /* Extracted Key value */ assert( sqlite3_mutex_held(pPage->pBt->mutex) ); assert( pPage->leaf==0 || pPage->leaf==1 ); @@ -1061,8 +1062,46 @@ static void btreeParseCellPtr( assert( pPage->noPayload==0 ); assert( pPage->intKeyLeaf ); assert( pPage->childPtrSize==0 ); - pIter = pCell + getVarint32(pCell, nPayload); - pIter += getVarint(pIter, (u64*)&pInfo->nKey); + pIter = pCell; + + /* The next block of code is equivalent to: + ** + ** pIter += getVarint32(pIter, nPayload); + ** + ** The code is inlined to avoid a function call. + */ + nPayload = *pIter; + if( nPayload>=0x80 ){ + u8 *pEnd = &pIter[8]; + nPayload &= 0x7f; + do{ + nPayload = (nPayload<<7) | (*++pIter & 0x7f); + }while( (*pIter)>=0x80 && pIter<pEnd ); + } + pIter++; + + /* The next block of code is equivalent to: + ** + ** pIter += getVarint(pIter, (u64*)&pInfo->nKey); + ** + ** The code is inlined to avoid a function call. + */ + iKey = *pIter; + if( iKey>=0x80 ){ + u8 *pEnd = &pIter[7]; + iKey &= 0x7f; + while(1){ + iKey = (iKey<<7) | (*++pIter & 0x7f); + if( (*pIter)<0x80 ) break; + if( pIter>=pEnd ){ + iKey = (iKey<<8) | *++pIter; + break; + } + } + } + pIter++; + + pInfo->nKey = *(i64*)&iKey; pInfo->nPayload = nPayload; pInfo->pPayload = pIter; testcase( nPayload==pPage->maxLocal ); @@ -1094,7 +1133,7 @@ static void btreeParseCellPtrIndex( pIter = pCell + pPage->childPtrSize; nPayload = *pIter; if( nPayload>=0x80 ){ - u8 *pEnd = &pIter[9]; + u8 *pEnd = &pIter[8]; nPayload &= 0x7f; do{ nPayload = (nPayload<<7) | (*++pIter & 0x7f); @@ -1155,7 +1194,7 @@ static u16 cellSizePtr(MemPage *pPage, u8 *pCell){ assert( pPage->noPayload==0 ); nSize = *pIter; if( nSize>=0x80 ){ - pEnd = &pIter[9]; + pEnd = &pIter[8]; nSize &= 0x7f; do{ nSize = (nSize<<7) | (*++pIter & 0x7f); |