In the Mem object, stop requiring that Mem.xDel be NULL when the MEM_Dyn

bit is clear.  Also reduce the amount of initialization of Mem objects.
All for a small size reduction and performance increase.

FossilOrigin-Name: fdddb477c89dabb9f7bf2d5ccb32534868df3a03
This commit is contained in:
drh 2014-09-17 16:41:15 +00:00
parent 0725cabe3a
commit d3b74200a8
6 changed files with 37 additions and 41 deletions

View File

@ -1,5 +1,5 @@
C Improved\sinterface\sto\sthe\sMem\sobject\shandling.\s\sSmall\ssize\sreduction\sand\nperformance\sincrease.
D 2014-09-17T14:52:46.727
C In\sthe\sMem\sobject,\sstop\srequiring\sthat\sMem.xDel\sbe\sNULL\swhen\sthe\sMEM_Dyn\nbit\sis\sclear.\s\sAlso\sreduce\sthe\samount\sof\sinitialization\sof\sMem\sobjects.\nAll\sfor\sa\ssmall\ssize\sreduction\sand\sperformance\sincrease.
D 2014-09-17T16:41:15.094
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in cf57f673d77606ab0f2d9627ca52a9ba1464146a
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@ -288,13 +288,13 @@ F src/update.c 729f6f18fc27740591d085e1172cebe311144bf0
F src/utf.c 8f634b93d41c089029dd503161a7d3e685d59a9c
F src/util.c 4006c01772bd8d8ac4306d523bbcee41d3e392d8
F src/vacuum.c 59f03f92bcff57faa6a8ca256eb29ccddfb0614a
F src/vdbe.c d39487782c0c6a2448bd1b351eba6a2dce101343
F src/vdbe.c d3c548ad4ea6a5549d2d0b502070e0523023ff97
F src/vdbe.h 09f5b4e3719fa454f252322b1cdab5cf1f361327
F src/vdbeInt.h 9d398055c873980b61ce0f7bf82140a8e4e2ccbc
F src/vdbeInt.h f90b0de6153f50de630a5a113537efb47083812f
F src/vdbeapi.c c6e63f913bcb12977731a8b12e7e5c5762981527
F src/vdbeaux.c 211ad29d51e01c44a0db1ab69b74c11c8de1cccf
F src/vdbeaux.c 9ac63bc59d2783df77e591e4c4fa8c1153a07eab
F src/vdbeblob.c 848238dc73e93e48432991bb5651bf87d865eca4
F src/vdbemem.c cf552a404f0e73a48bd266699aa27f0df26b096b
F src/vdbemem.c 8b5e1083fed2da94e315858a7edf5604a5b91804
F src/vdbesort.c 09efa5e5098d1a159cd21f588eb118e4fe87cfde
F src/vdbetrace.c 16d39c1ef7d1f4a3a7464bea3b7b4bdd7849c415
F src/vtab.c 019dbfd0406a7447c990e1f7bd1dfcdb8895697f
@ -1198,7 +1198,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P 2598aedc5dd2bac67e2e518a31f2803e469c2ba6
R f63e98cc1bcae44946c79c20cdee7610
P 4e437844322cc20eef92928b53fa6b37eded586e
R 8244691fd19236cfb5e445e4012669fa
U drh
Z 1559702e8c6b5218f324b4f43d7dc2c7
Z ef23a1637c5e3046b6cead80453b022e

View File

@ -1 +1 @@
4e437844322cc20eef92928b53fa6b37eded586e
fdddb477c89dabb9f7bf2d5ccb32534868df3a03

View File

@ -1174,7 +1174,6 @@ case OP_Move: {
}
#endif
pIn1->flags = MEM_Undefined;
pIn1->xDel = 0;
pIn1->zMalloc = zMalloc;
REGISTER_TRACE(p2++, pOut);
pIn1++;
@ -2645,7 +2644,6 @@ case OP_MakeRecord: {
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
pOut->n = (int)nByte;
pOut->flags = MEM_Blob;
pOut->xDel = 0;
if( nZero ){
pOut->u.nZero = nZero;
pOut->flags |= MEM_Zero;
@ -4755,7 +4753,7 @@ case OP_IdxRowid: { /* out2-prerelease */
assert( pC->isTable==0 );
if( !pC->nullRow ){
rowid = 0; /* Not needed. Only used to silence a warning. */
rc = sqlite3VdbeIdxRowid(pCrsr, &rowid);
rc = sqlite3VdbeIdxRowid(db, pCrsr, &rowid);
if( rc!=SQLITE_OK ){
goto abort_due_to_error;
}
@ -4839,7 +4837,7 @@ case OP_IdxGE: { /* jump */
{ int i; for(i=0; i<r.nField; i++) assert( memIsValid(&r.aMem[i]) ); }
#endif
res = 0; /* Not needed. Only used to silence a warning. */
rc = sqlite3VdbeIdxKeyCompare(pC, &r, &res);
rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
assert( (OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1) );
if( (pOp->opcode&1)==(OP_IdxLT&1) ){
assert( pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT );
@ -5609,11 +5607,7 @@ case OP_AggStep: {
assert( pOp->p3>0 && pOp->p3<=(p->nMem-p->nCursor) );
ctx.pMem = pMem = &aMem[pOp->p3];
pMem->n++;
t.flags = MEM_Null;
t.z = 0;
t.zMalloc = 0;
t.xDel = 0;
t.db = db;
sqlite3VdbeMemInit(&t, db, MEM_Null);
ctx.pOut = &t;
ctx.isError = 0;
ctx.pColl = 0;

View File

@ -176,7 +176,7 @@ struct Mem {
char *zMalloc; /* Dynamic buffer allocated by sqlite3_malloc() */
/* ShallowCopy only needs to copy the information above */
sqlite3 *db; /* The associated database connection */
void (*xDel)(void*);/* If not null, call this function to delete Mem.z */
void (*xDel)(void*);/* Destructor for Mem.z - only valid if MEM_Dyn */
#ifdef SQLITE_DEBUG
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
void *pFiller; /* So that sizeof(Mem) is a multiple of 8 */
@ -397,8 +397,8 @@ u32 sqlite3VdbeSerialGet(const unsigned char*, u32, Mem*);
void sqlite3VdbeDeleteAuxData(Vdbe*, int, int);
int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
int sqlite3VdbeIdxKeyCompare(VdbeCursor*,UnpackedRecord*,int*);
int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
int sqlite3VdbeIdxKeyCompare(sqlite3*,VdbeCursor*,UnpackedRecord*,int*);
int sqlite3VdbeIdxRowid(sqlite3*, BtCursor*, i64*);
int sqlite3VdbeExec(Vdbe*);
int sqlite3VdbeList(Vdbe*);
int sqlite3VdbeHalt(Vdbe*);
@ -415,6 +415,7 @@ void sqlite3VdbeMemSetInt64(Mem*, i64);
#else
void sqlite3VdbeMemSetDouble(Mem*, double);
#endif
void sqlite3VdbeMemInit(Mem*,sqlite3*,u16);
void sqlite3VdbeMemSetNull(Mem*);
void sqlite3VdbeMemSetZeroBlob(Mem*,int);
void sqlite3VdbeMemSetRowSet(Mem*);

View File

@ -3085,7 +3085,6 @@ u32 sqlite3VdbeSerialGet(
static const u16 aFlag[] = { MEM_Blob|MEM_Ephem, MEM_Str|MEM_Ephem };
pMem->z = (char *)buf;
pMem->n = (serial_type-12)/2;
pMem->xDel = 0;
pMem->flags = aFlag[serial_type&1];
return pMem->n;
}
@ -3306,7 +3305,6 @@ static int vdbeCompareMemString(
c1.db = c2.db = pMem1->db;
c1.flags = c2.flags = 0;
c1.zMalloc = c2.zMalloc = 0;
c1.xDel = c2.xDel = 0;
sqlite3VdbeMemShallowCopy(&c1, pMem1, MEM_Ephem);
sqlite3VdbeMemShallowCopy(&c2, pMem2, MEM_Ephem);
v1 = sqlite3ValueText((sqlite3_value*)&c1, pColl->enc);
@ -3877,7 +3875,7 @@ RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *p){
** pCur might be pointing to text obtained from a corrupt database file.
** So the content cannot be trusted. Do appropriate checks on the content.
*/
int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
int sqlite3VdbeIdxRowid(sqlite3 *db, BtCursor *pCur, i64 *rowid){
i64 nCellKey = 0;
int rc;
u32 szHdr; /* Size of the header */
@ -3896,7 +3894,7 @@ int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
assert( (nCellKey & SQLITE_MAX_U32)==(u64)nCellKey );
/* Read in the complete content of the index entry */
memset(&m, 0, sizeof(m));
sqlite3VdbeMemInit(&m, db, 0);
rc = sqlite3VdbeMemFromBtree(pCur, 0, (u32)nCellKey, 1, &m);
if( rc ){
return rc;
@ -3956,6 +3954,7 @@ idx_rowid_corruption:
** of the keys prior to the final rowid, not the entire key.
*/
int sqlite3VdbeIdxKeyCompare(
sqlite3 *db, /* Database connection */
VdbeCursor *pC, /* The cursor to compare against */
UnpackedRecord *pUnpacked, /* Unpacked version of key */
int *res /* Write the comparison result here */
@ -3974,7 +3973,7 @@ int sqlite3VdbeIdxKeyCompare(
*res = 0;
return SQLITE_CORRUPT_BKPT;
}
memset(&m, 0, sizeof(m));
sqlite3VdbeMemInit(&m, db, 0);
rc = sqlite3VdbeMemFromBtree(pC->pCursor, 0, (u32)nCellKey, 1, &m);
if( rc ){
return rc;

View File

@ -26,11 +26,10 @@
** this: assert( sqlite3VdbeCheckMemInvariants(pMem) );
*/
int sqlite3VdbeCheckMemInvariants(Mem *p){
/* The MEM_Dyn bit is set if and only if Mem.xDel is a non-NULL destructor
** function for Mem.z
/* If MEM_Dyn is set then Mem.xDel!=0.
** Mem.xDel is might not be initialized if MEM_Dyn is clear.
*/
assert( (p->flags & MEM_Dyn)==0 || p->xDel!=0 );
assert( (p->flags & MEM_Dyn)!=0 || p->xDel==0 );
/* If p holds a string or blob, the Mem.z must point to exactly
** one of the following:
@ -136,7 +135,6 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){
pMem->z = pMem->zMalloc;
pMem->flags &= ~(MEM_Dyn|MEM_Ephem|MEM_Static);
pMem->xDel = 0;
return SQLITE_OK;
}
@ -299,7 +297,7 @@ int sqlite3VdbeMemFinalize(Mem *pMem, FuncDef *pFunc){
ctx.pMem = pMem;
ctx.pFunc = pFunc;
pFunc->xFinalize(&ctx); /* IMP: R-24505-23230 */
assert( 0==(pMem->flags&MEM_Dyn) && !pMem->xDel );
assert( (pMem->flags & MEM_Dyn)==0 );
sqlite3DbFree(pMem->db, pMem->zMalloc);
memcpy(pMem, &t, sizeof(t));
rc = ctx.isError;
@ -328,7 +326,6 @@ static SQLITE_NOINLINE void vdbeMemClearExternAndSetNull(Mem *p){
assert( (p->flags&MEM_RowSet)==0 );
assert( p->xDel!=SQLITE_DYNAMIC && p->xDel!=0 );
p->xDel((void *)p->z);
p->xDel = 0;
}else if( p->flags&MEM_RowSet ){
sqlite3RowSetClear(p->u.pRowSet);
}else if( p->flags&MEM_Frame ){
@ -373,7 +370,6 @@ void sqlite3VdbeMemRelease(Mem *p){
if( VdbeMemDynamic(p) || p->zMalloc ){
vdbeMemClear(p);
}
assert( p->xDel==0 );
}
/*
@ -585,6 +581,18 @@ void sqlite3VdbeMemCast(Mem *pMem, u8 aff, u8 encoding){
}
}
/*
** Initialize bulk memory to be a consistent Mem object.
**
** The minimum amount of initialization feasible is performed.
*/
void sqlite3VdbeMemInit(Mem *pMem, sqlite3 *db, u16 flags){
assert( (flags & ~MEM_TypeMask)==0 );
pMem->flags = flags;
pMem->db = db;
pMem->zMalloc = 0;
}
/*
** Delete any previous value and set the value stored in *pMem to NULL.
@ -736,7 +744,6 @@ void sqlite3VdbeMemShallowCopy(Mem *pTo, const Mem *pFrom, int srcType){
assert( pTo->db==pFrom->db );
if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
memcpy(pTo, pFrom, MEMCELLSIZE);
assert( pTo->xDel==0 );
if( (pFrom->flags&MEM_Static)==0 ){
pTo->flags &= ~(MEM_Dyn|MEM_Static|MEM_Ephem);
assert( srcType==MEM_Ephem || srcType==MEM_Static );
@ -756,8 +763,6 @@ int sqlite3VdbeMemCopy(Mem *pTo, const Mem *pFrom){
if( VdbeMemDynamic(pTo) ) vdbeMemClearExternAndSetNull(pTo);
memcpy(pTo, pFrom, MEMCELLSIZE);
pTo->flags &= ~MEM_Dyn;
assert( pTo->xDel==0 );
if( pTo->flags&(MEM_Str|MEM_Blob) ){
if( 0==(pFrom->flags&MEM_Static) ){
pTo->flags |= MEM_Ephem;
@ -782,7 +787,6 @@ void sqlite3VdbeMemMove(Mem *pTo, Mem *pFrom){
sqlite3VdbeMemRelease(pTo);
memcpy(pTo, pFrom, sizeof(Mem));
pFrom->flags = MEM_Null;
pFrom->xDel = 0;
pFrom->zMalloc = 0;
}
@ -857,7 +861,6 @@ int sqlite3VdbeMemSetStr(
}else if( xDel==SQLITE_DYNAMIC ){
sqlite3VdbeMemRelease(pMem);
pMem->zMalloc = pMem->z = (char *)z;
pMem->xDel = 0;
}else{
sqlite3VdbeMemRelease(pMem);
pMem->z = (char *)z;
@ -910,7 +913,7 @@ int sqlite3VdbeMemFromBtree(
int rc = SQLITE_OK; /* Return code */
assert( sqlite3BtreeCursorIsValid(pCur) );
assert( pMem->xDel==0 );
assert( !VdbeMemDynamic(pMem) );
/* Note: the calls to BtreeKeyFetch() and DataFetch() below assert()
** that both the BtShared and database handle mutexes are held. */
@ -923,7 +926,6 @@ int sqlite3VdbeMemFromBtree(
assert( zData!=0 );
if( offset+amt<=available ){
sqlite3VdbeMemRelease(pMem);
pMem->z = &zData[offset];
pMem->flags = MEM_Blob|MEM_Ephem;
pMem->n = (int)amt;