Simplifications to the way UnpackedRecord objects are allocated. Smaller
and faster code that also fixes a subtle (currently unreachable) bug. FossilOrigin-Name: f7ab01f254cd9d7006b8dec29adb234a671b8e6f
This commit is contained in:
parent
f99dd359d0
commit
a582b01698
22
manifest
22
manifest
@ -1,5 +1,5 @@
|
||||
C Change\sthe\sOP_IfNotZero\sopcode\sso\sthat\sit\sdecrements\sregister\sP1\sby\s1\srather\nthan\sthe\svalue\sin\sP3,\sand\sso\sthat\sit\sonly\sdecrements\sif\soriginally\spositive.\nThis\savoids\sdecrementing\sthe\ssmallest\s64-bit\ssigned\sinteger.
|
||||
D 2016-12-18T17:42:00.870
|
||||
C Simplifications\sto\sthe\sway\sUnpackedRecord\sobjects\sare\sallocated.\s\sSmaller\nand\sfaster\scode\sthat\salso\sfixes\sa\ssubtle\s(currently\sunreachable)\sbug.
|
||||
D 2016-12-21T19:45:54.698
|
||||
F Makefile.in 41bd4cad981487345c4a84081074bcdb876e4b2e
|
||||
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
|
||||
F Makefile.msc b8ca53350ae545e3562403d5da2a69cec79308da
|
||||
@ -331,7 +331,7 @@ F src/auth.c 930b376a9c56998557367e6f7f8aaeac82a2a792
|
||||
F src/backup.c faf17e60b43233c214aae6a8179d24503a61e83b
|
||||
F src/bitvec.c 17ea48eff8ba979f1f5b04cc484c7bb2be632f33
|
||||
F src/btmutex.c bc87dd3b062cc26edfe79918de2200ccb8d41e73
|
||||
F src/btree.c b2055dff0b94e03eaad48a760984a2d8e39244e6
|
||||
F src/btree.c 2e07a5a6d705c1439392460f4044ea4179d9cd40
|
||||
F src/btree.h 2349a588abcd7e0c04f984e15c5c777b61637583
|
||||
F src/btreeInt.h 10c4b77c2fb399580babbcc7cf652ac10dba796e
|
||||
F src/build.c 52970b6cf3cf3107551a5d6dd668b0b261b0b491
|
||||
@ -455,14 +455,14 @@ F src/update.c 1da7c462110bffed442a42884cb0d528c1db46d8
|
||||
F src/utf.c 699001c79f28e48e9bcdf8a463da029ea660540c
|
||||
F src/util.c e68e8ced7328f22d2cf7b4c898c394a0de34cdf1
|
||||
F src/vacuum.c 33c174b28886b2faf26e503b5a49a1c01a9b1c16
|
||||
F src/vdbe.c 4537452b85817772f159751d6b05799f3f4b09f5
|
||||
F src/vdbe.h 0c74f6305fb43b9b282dacaff102272370e327d4
|
||||
F src/vdbe.c 0106e0d4f0d39aced35c150a6919d2878df6b1e0
|
||||
F src/vdbe.h 50ee139f9c68fff91be1d717ed3a6abbd496919c
|
||||
F src/vdbeInt.h 42e498dbe96475dbb3fda3d85d8fd2a87eff60a2
|
||||
F src/vdbeapi.c ea4e2dc2213cc6bd7bee375a29a9b51c31b93ae0
|
||||
F src/vdbeaux.c f5edc89007f8a49e224089a4a4dddbc11bd38213
|
||||
F src/vdbeapi.c 129a2a1103e29fe839e137c641ff42b8066667b5
|
||||
F src/vdbeaux.c 7f67112cc57b2fa37b777fbf03eb32c96b337cfe
|
||||
F src/vdbeblob.c f4f98ea672b242f807c08c92c7faaa79e5091b65
|
||||
F src/vdbemem.c d3fd85b7b7ef3eb75de29c6d7e1d10d3ca78b4fd
|
||||
F src/vdbesort.c bb34eed4fb52e11ac037dccea4ee3190594c7f9e
|
||||
F src/vdbesort.c eda25cb2d1727efca6f7862fea32b8aa33c0face
|
||||
F src/vdbetrace.c 41963d5376f0349842b5fc4aaaaacd7d9cdc0834
|
||||
F src/vtab.c c4bbe0f870f52036553f8098aee0703997f0577a
|
||||
F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
|
||||
@ -1539,7 +1539,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 50325abe79b6a79b09ec6a1cee7d80ca02337428
|
||||
R e3435f7f9ecf849784b4c50691f0f18b
|
||||
P 165c044686212fbf7182dd560ad1e57eb4cc9838
|
||||
R 4dcc327309935c00dd451588970c060d
|
||||
U drh
|
||||
Z 8b4cd82f585875ac24b32af2b88bc83b
|
||||
Z 2858688c4db6360d8c3b1c8fd6aab8f2
|
||||
|
@ -1 +1 @@
|
||||
165c044686212fbf7182dd560ad1e57eb4cc9838
|
||||
f7ab01f254cd9d7006b8dec29adb234a671b8e6f
|
15
src/btree.c
15
src/btree.c
@ -763,26 +763,23 @@ static int btreeMoveto(
|
||||
){
|
||||
int rc; /* Status code */
|
||||
UnpackedRecord *pIdxKey; /* Unpacked index key */
|
||||
char aSpace[384]; /* Temp space for pIdxKey - to avoid a malloc */
|
||||
char *pFree = 0;
|
||||
|
||||
if( pKey ){
|
||||
assert( nKey==(i64)(int)nKey );
|
||||
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
|
||||
pCur->pKeyInfo, aSpace, sizeof(aSpace), &pFree
|
||||
);
|
||||
pIdxKey = sqlite3VdbeAllocUnpackedRecord(pCur->pKeyInfo);
|
||||
if( pIdxKey==0 ) return SQLITE_NOMEM_BKPT;
|
||||
sqlite3VdbeRecordUnpack(pCur->pKeyInfo, (int)nKey, pKey, pIdxKey);
|
||||
if( pIdxKey->nField==0 ){
|
||||
sqlite3DbFree(pCur->pKeyInfo->db, pFree);
|
||||
return SQLITE_CORRUPT_BKPT;
|
||||
rc = SQLITE_CORRUPT_BKPT;
|
||||
goto moveto_done;
|
||||
}
|
||||
}else{
|
||||
pIdxKey = 0;
|
||||
}
|
||||
rc = sqlite3BtreeMovetoUnpacked(pCur, pIdxKey, nKey, bias, pRes);
|
||||
if( pFree ){
|
||||
sqlite3DbFree(pCur->pKeyInfo->db, pFree);
|
||||
moveto_done:
|
||||
if( pIdxKey ){
|
||||
sqlite3DbFree(pCur->pKeyInfo->db, pIdxKey);
|
||||
}
|
||||
return rc;
|
||||
}
|
||||
|
11
src/vdbe.c
11
src/vdbe.c
@ -3985,10 +3985,9 @@ case OP_Found: { /* jump, in3 */
|
||||
int ii;
|
||||
VdbeCursor *pC;
|
||||
int res;
|
||||
char *pFree;
|
||||
UnpackedRecord *pFree;
|
||||
UnpackedRecord *pIdxKey;
|
||||
UnpackedRecord r;
|
||||
char aTempRec[ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*4 + 7];
|
||||
|
||||
#ifdef SQLITE_TEST
|
||||
if( pOp->opcode!=OP_NoConflict ) sqlite3_found_count++;
|
||||
@ -4005,7 +4004,6 @@ case OP_Found: { /* jump, in3 */
|
||||
assert( pC->eCurType==CURTYPE_BTREE );
|
||||
assert( pC->uc.pCursor!=0 );
|
||||
assert( pC->isTable==0 );
|
||||
pFree = 0;
|
||||
if( pOp->p4.i>0 ){
|
||||
r.pKeyInfo = pC->pKeyInfo;
|
||||
r.nField = (u16)pOp->p4.i;
|
||||
@ -4018,10 +4016,9 @@ case OP_Found: { /* jump, in3 */
|
||||
}
|
||||
#endif
|
||||
pIdxKey = &r;
|
||||
pFree = 0;
|
||||
}else{
|
||||
pIdxKey = sqlite3VdbeAllocUnpackedRecord(
|
||||
pC->pKeyInfo, aTempRec, sizeof(aTempRec), &pFree
|
||||
);
|
||||
pFree = pIdxKey = sqlite3VdbeAllocUnpackedRecord(pC->pKeyInfo);
|
||||
if( pIdxKey==0 ) goto no_mem;
|
||||
assert( pIn3->flags & MEM_Blob );
|
||||
(void)ExpandBlob(pIn3);
|
||||
@ -4041,7 +4038,7 @@ case OP_Found: { /* jump, in3 */
|
||||
}
|
||||
}
|
||||
rc = sqlite3BtreeMovetoUnpacked(pC->uc.pCursor, pIdxKey, 0, 0, &res);
|
||||
sqlite3DbFree(db, pFree);
|
||||
if( pFree ) sqlite3DbFree(db, pFree);
|
||||
if( rc!=SQLITE_OK ){
|
||||
goto abort_due_to_error;
|
||||
}
|
||||
|
@ -233,7 +233,7 @@ int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
|
||||
void sqlite3VdbeRecordUnpack(KeyInfo*,int,const void*,UnpackedRecord*);
|
||||
int sqlite3VdbeRecordCompare(int,const void*,UnpackedRecord*);
|
||||
int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
|
||||
UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *, char *, int, char **);
|
||||
UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo*);
|
||||
|
||||
typedef int (*RecordCompare)(int,const void*,UnpackedRecord*);
|
||||
RecordCompare sqlite3VdbeFindCompare(UnpackedRecord*);
|
||||
|
@ -1657,10 +1657,9 @@ static UnpackedRecord *vdbeUnpackRecord(
|
||||
int nKey,
|
||||
const void *pKey
|
||||
){
|
||||
char *dummy; /* Dummy argument for AllocUnpackedRecord() */
|
||||
UnpackedRecord *pRet; /* Return value */
|
||||
|
||||
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo, 0, 0, &dummy);
|
||||
pRet = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
|
||||
if( pRet ){
|
||||
memset(pRet->aMem, 0, sizeof(Mem)*(pKeyInfo->nField+1));
|
||||
sqlite3VdbeRecordUnpack(pKeyInfo, nKey, pKey, pRet);
|
||||
|
@ -3494,30 +3494,13 @@ u32 sqlite3VdbeSerialGet(
|
||||
** If an OOM error occurs, NULL is returned.
|
||||
*/
|
||||
UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(
|
||||
KeyInfo *pKeyInfo, /* Description of the record */
|
||||
char *pSpace, /* Unaligned space available */
|
||||
int szSpace, /* Size of pSpace[] in bytes */
|
||||
char **ppFree /* OUT: Caller should free this pointer */
|
||||
KeyInfo *pKeyInfo /* Description of the record */
|
||||
){
|
||||
UnpackedRecord *p; /* Unpacked record to return */
|
||||
int nOff; /* Increment pSpace by nOff to align it */
|
||||
int nByte; /* Number of bytes required for *p */
|
||||
|
||||
/* We want to shift the pointer pSpace up such that it is 8-byte aligned.
|
||||
** Thus, we need to calculate a value, nOff, between 0 and 7, to shift
|
||||
** it by. If pSpace is already 8-byte aligned, nOff should be zero.
|
||||
*/
|
||||
nOff = (8 - (SQLITE_PTR_TO_INT(pSpace) & 7)) & 7;
|
||||
nByte = ROUND8(sizeof(UnpackedRecord)) + sizeof(Mem)*(pKeyInfo->nField+1);
|
||||
if( nByte>szSpace+nOff ){
|
||||
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
|
||||
*ppFree = (char *)p;
|
||||
if( !p ) return 0;
|
||||
}else{
|
||||
p = (UnpackedRecord*)&pSpace[nOff];
|
||||
*ppFree = 0;
|
||||
}
|
||||
|
||||
p = (UnpackedRecord *)sqlite3DbMallocRaw(pKeyInfo->db, nByte);
|
||||
if( !p ) return 0;
|
||||
p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
|
||||
assert( pKeyInfo->aSortOrder!=0 );
|
||||
p->pKeyInfo = pKeyInfo;
|
||||
|
@ -1327,12 +1327,8 @@ static int vdbeSorterOpenTempFile(
|
||||
*/
|
||||
static int vdbeSortAllocUnpacked(SortSubtask *pTask){
|
||||
if( pTask->pUnpacked==0 ){
|
||||
char *pFree;
|
||||
pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(
|
||||
pTask->pSorter->pKeyInfo, 0, 0, &pFree
|
||||
);
|
||||
assert( pTask->pUnpacked==(UnpackedRecord*)pFree );
|
||||
if( pFree==0 ) return SQLITE_NOMEM_BKPT;
|
||||
pTask->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pTask->pSorter->pKeyInfo);
|
||||
if( pTask->pUnpacked==0 ) return SQLITE_NOMEM_BKPT;
|
||||
pTask->pUnpacked->nField = pTask->pSorter->pKeyInfo->nField;
|
||||
pTask->pUnpacked->errCode = 0;
|
||||
}
|
||||
@ -2733,9 +2729,7 @@ int sqlite3VdbeSorterCompare(
|
||||
r2 = pSorter->pUnpacked;
|
||||
pKeyInfo = pCsr->pKeyInfo;
|
||||
if( r2==0 ){
|
||||
char *p;
|
||||
r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo,0,0,&p);
|
||||
assert( pSorter->pUnpacked==(UnpackedRecord*)p );
|
||||
r2 = pSorter->pUnpacked = sqlite3VdbeAllocUnpackedRecord(pKeyInfo);
|
||||
if( r2==0 ) return SQLITE_NOMEM_BKPT;
|
||||
r2->nField = nKeyCol;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user