Faster and smaller implementation of sqlite3_value_type().
FossilOrigin-Name: 5708bc24b8cab623b833121183042b43e5a7021b
This commit is contained in:
parent
5574e3f456
commit
1b27b8c0a0
22
manifest
22
manifest
@ -1,5 +1,5 @@
|
||||
C Add\sa\scompound-query\stest\sto\sthe\sspeedtest1\stest\sprogram.
|
||||
D 2014-02-09T23:59:28.966
|
||||
C Faster\sand\ssmaller\simplementation\sof\ssqlite3_value_type().
|
||||
D 2014-02-10T03:21:57.367
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in 2ef13430cd359f7b361bb863504e227b25cc7f81
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -233,7 +233,7 @@ F src/test1.c 2401eee14a4309a7cfe2aeb2f30ad517a1d9c299
|
||||
F src/test2.c 7355101c085304b90024f2261e056cdff13c6c35
|
||||
F src/test3.c 1c0e5d6f080b8e33c1ce8b3078e7013fdbcd560c
|
||||
F src/test4.c 9b32d22f5f150abe23c1830e2057c4037c45b3df
|
||||
F src/test5.c a6d1ac55ac054d0b2b8f37b5e655b6c92645a013
|
||||
F src/test5.c 41e6e732f14a54c7b47f753e364700760f6521b0
|
||||
F src/test6.c 41cacf3b0dd180823919bf9e1fbab287c9266723
|
||||
F src/test7.c 72b732baa5642f795655ba1126ea032af46ecfd2
|
||||
F src/test8.c 54ccd7b1df5062f0ecbf50a8f7b618f8b1f13b20
|
||||
@ -280,13 +280,13 @@ F src/update.c a7df6fffce6bfedc578fda6136dd33e34a63f8ee
|
||||
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
|
||||
F src/util.c 15ac2627f548f5481d0d7e6c4eb67be673027695
|
||||
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
|
||||
F src/vdbe.c 78b41fd0a3b3ab4647e3bf99905fb65831a1a92a
|
||||
F src/vdbe.c 66c3e5c49ff61aaa3e3182fb9962ceddb847b05f
|
||||
F src/vdbe.h e6c4c610fcabad4fa80ebb1efc6822a9367e2b26
|
||||
F src/vdbeInt.h 6714e9eb5c3a481976d32ca767f03ac0469fc9df
|
||||
F src/vdbeapi.c ce4e68ea4842cc6081046f533d088dcf01d247ad
|
||||
F src/vdbeaux.c 379343f1d98b60b0771366e5955f3cab34f1a3ca
|
||||
F src/vdbeInt.h 5286af9067cabdb8ba57b87c0c988a931be6c6c8
|
||||
F src/vdbeapi.c 5bc41aaea448a7fc250902c418f1795859be3820
|
||||
F src/vdbeaux.c dac6e571262a322b2f889752a8dd36549bdacd2b
|
||||
F src/vdbeblob.c 9542e116c1db5ed813977581d506c176e117c0ec
|
||||
F src/vdbemem.c c0bcc02d6816ab4218ac0f94b63c8ee78a0f739f
|
||||
F src/vdbemem.c 06603e8e9d2f3247b68c6bbe4bd37fb6721b5bda
|
||||
F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147
|
||||
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
|
||||
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
|
||||
@ -1152,7 +1152,7 @@ F tool/vdbe-compress.tcl 0cf56e9263a152b84da86e75a5c0cdcdb7a47891
|
||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
|
||||
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
|
||||
P 67bfd59d9087a987f15f6148efa1ff104983e1fb
|
||||
R 08e9f131a35b941b5219bd5647483bf9
|
||||
P 532995759114ab7a7cba18cc9d8820d78eb1a96e
|
||||
R 1d6572df35f58f7e82be516ccbec8b1d
|
||||
U drh
|
||||
Z 03478c9c29bcc9ab89e223c27b70af04
|
||||
Z d879d19c9c74c4f3aa3952d43b5ccba0
|
||||
|
@ -1 +1 @@
|
||||
532995759114ab7a7cba18cc9d8820d78eb1a96e
|
||||
5708bc24b8cab623b833121183042b43e5a7021b
|
@ -76,7 +76,7 @@ static int test_value_overhead(
|
||||
|
||||
val.flags = MEM_Str|MEM_Term|MEM_Static;
|
||||
val.z = "hello world";
|
||||
val.type = SQLITE_TEXT;
|
||||
val.memType = MEM_Str;
|
||||
val.enc = SQLITE_UTF8;
|
||||
|
||||
for(i=0; i<repeat_count; i++){
|
||||
|
32
src/vdbe.c
32
src/vdbe.c
@ -133,30 +133,6 @@ int sqlite3_found_count = 0;
|
||||
/* Return true if the cursor was opened using the OP_OpenSorter opcode. */
|
||||
#define isSorter(x) ((x)->pSorter!=0)
|
||||
|
||||
/*
|
||||
** Argument pMem points at a register that will be passed to a
|
||||
** user-defined function or returned to the user as the result of a query.
|
||||
** This routine sets the pMem->type variable used by the sqlite3_value_*()
|
||||
** routines.
|
||||
*/
|
||||
void sqlite3VdbeMemStoreType(Mem *pMem){
|
||||
int flags = pMem->flags;
|
||||
if( flags & MEM_Null ){
|
||||
pMem->type = SQLITE_NULL;
|
||||
}
|
||||
else if( flags & MEM_Int ){
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
}
|
||||
else if( flags & MEM_Real ){
|
||||
pMem->type = SQLITE_FLOAT;
|
||||
}
|
||||
else if( flags & MEM_Str ){
|
||||
pMem->type = SQLITE_TEXT;
|
||||
}else{
|
||||
pMem->type = SQLITE_BLOB;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
** Allocate VdbeCursor number iCur. Return a pointer to it. Return NULL
|
||||
** if we run out of memory.
|
||||
@ -285,12 +261,14 @@ static void applyAffinity(
|
||||
** loss of information and return the revised type of the argument.
|
||||
*/
|
||||
int sqlite3_value_numeric_type(sqlite3_value *pVal){
|
||||
Mem *pMem = (Mem*)pVal;
|
||||
if( pMem->type==SQLITE_TEXT ){
|
||||
int eType = sqlite3_value_type(pVal);
|
||||
if( eType==SQLITE_TEXT ){
|
||||
Mem *pMem = (Mem*)pVal;
|
||||
applyNumericAffinity(pMem);
|
||||
sqlite3VdbeMemStoreType(pMem);
|
||||
eType = sqlite3_value_type(pVal);
|
||||
}
|
||||
return pMem->type;
|
||||
return eType;
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -168,7 +168,7 @@ struct Mem {
|
||||
} u;
|
||||
int n; /* Number of characters in string value, excluding '\0' */
|
||||
u16 flags; /* Some combination of MEM_Null, MEM_Str, MEM_Dyn, etc. */
|
||||
u8 type; /* One of SQLITE_NULL, SQLITE_TEXT, SQLITE_INTEGER, etc */
|
||||
u8 memType; /* Lower 5 bits of flags */
|
||||
u8 enc; /* SQLITE_UTF8, SQLITE_UTF16BE, SQLITE_UTF16LE */
|
||||
#ifdef SQLITE_DEBUG
|
||||
Mem *pScopyFrom; /* This Mem is a shallow copy of pScopyFrom */
|
||||
@ -434,7 +434,8 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve);
|
||||
int sqlite3VdbeCloseStatement(Vdbe *, int);
|
||||
void sqlite3VdbeFrameDelete(VdbeFrame*);
|
||||
int sqlite3VdbeFrameRestore(VdbeFrame *);
|
||||
void sqlite3VdbeMemStoreType(Mem *pMem);
|
||||
#define sqlite3VdbeMemStoreType(X) (X)->memType = (u8)((X)->flags&0x1f)
|
||||
/* void sqlite3VdbeMemStoreType(Mem *pMem); */
|
||||
int sqlite3VdbeTransferError(Vdbe *p);
|
||||
|
||||
int sqlite3VdbeSorterInit(sqlite3 *, VdbeCursor *);
|
||||
|
@ -172,7 +172,41 @@ const void *sqlite3_value_text16le(sqlite3_value *pVal){
|
||||
}
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_value_type(sqlite3_value* pVal){
|
||||
return pVal->type;
|
||||
static const u8 aType[] = {
|
||||
SQLITE_BLOB, /* 0x00 */
|
||||
SQLITE_NULL, /* 0x01 */
|
||||
SQLITE_TEXT, /* 0x02 */
|
||||
SQLITE_NULL, /* 0x03 */
|
||||
SQLITE_INTEGER, /* 0x04 */
|
||||
SQLITE_NULL, /* 0x05 */
|
||||
SQLITE_INTEGER, /* 0x06 */
|
||||
SQLITE_NULL, /* 0x07 */
|
||||
SQLITE_FLOAT, /* 0x08 */
|
||||
SQLITE_NULL, /* 0x09 */
|
||||
SQLITE_FLOAT, /* 0x0a */
|
||||
SQLITE_NULL, /* 0x0b */
|
||||
SQLITE_INTEGER, /* 0x0c */
|
||||
SQLITE_NULL, /* 0x0d */
|
||||
SQLITE_INTEGER, /* 0x0e */
|
||||
SQLITE_NULL, /* 0x0f */
|
||||
SQLITE_BLOB, /* 0x10 */
|
||||
SQLITE_NULL, /* 0x11 */
|
||||
SQLITE_TEXT, /* 0x12 */
|
||||
SQLITE_NULL, /* 0x13 */
|
||||
SQLITE_INTEGER, /* 0x14 */
|
||||
SQLITE_NULL, /* 0x15 */
|
||||
SQLITE_INTEGER, /* 0x16 */
|
||||
SQLITE_NULL, /* 0x17 */
|
||||
SQLITE_FLOAT, /* 0x18 */
|
||||
SQLITE_NULL, /* 0x19 */
|
||||
SQLITE_FLOAT, /* 0x1a */
|
||||
SQLITE_NULL, /* 0x1b */
|
||||
SQLITE_INTEGER, /* 0x1c */
|
||||
SQLITE_NULL, /* 0x1d */
|
||||
SQLITE_INTEGER, /* 0x1e */
|
||||
SQLITE_NULL, /* 0x1f */
|
||||
};
|
||||
return aType[pVal->memType&0x1f];
|
||||
}
|
||||
|
||||
/**************************** sqlite3_result_ *******************************
|
||||
@ -1131,7 +1165,7 @@ int sqlite3_bind_text16(
|
||||
#endif /* SQLITE_OMIT_UTF16 */
|
||||
int sqlite3_bind_value(sqlite3_stmt *pStmt, int i, const sqlite3_value *pValue){
|
||||
int rc;
|
||||
switch( pValue->type ){
|
||||
switch( sqlite3_value_type((sqlite3_value*)pValue) ){
|
||||
case SQLITE_INTEGER: {
|
||||
rc = sqlite3_bind_int64(pStmt, i, pValue->u.i);
|
||||
break;
|
||||
|
@ -1345,7 +1345,7 @@ int sqlite3VdbeList(
|
||||
}
|
||||
if( p->explain==1 ){
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
pMem->memType = MEM_Int;
|
||||
pMem->u.i = i; /* Program counter */
|
||||
pMem++;
|
||||
|
||||
@ -1353,7 +1353,7 @@ int sqlite3VdbeList(
|
||||
pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */
|
||||
assert( pMem->z!=0 );
|
||||
pMem->n = sqlite3Strlen30(pMem->z);
|
||||
pMem->type = SQLITE_TEXT;
|
||||
pMem->memType = MEM_Str;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
pMem++;
|
||||
|
||||
@ -1379,17 +1379,17 @@ int sqlite3VdbeList(
|
||||
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->u.i = pOp->p1; /* P1 */
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
pMem->memType = MEM_Int;
|
||||
pMem++;
|
||||
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->u.i = pOp->p2; /* P2 */
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
pMem->memType = MEM_Int;
|
||||
pMem++;
|
||||
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->u.i = pOp->p3; /* P3 */
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
pMem->memType = MEM_Int;
|
||||
pMem++;
|
||||
|
||||
if( sqlite3VdbeMemGrow(pMem, 32, 0) ){ /* P4 */
|
||||
@ -1405,7 +1405,7 @@ int sqlite3VdbeList(
|
||||
pMem->n = sqlite3Strlen30(pMem->z);
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
}
|
||||
pMem->type = SQLITE_TEXT;
|
||||
pMem->memType = MEM_Str;
|
||||
pMem++;
|
||||
|
||||
if( p->explain==1 ){
|
||||
@ -1416,7 +1416,7 @@ int sqlite3VdbeList(
|
||||
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
|
||||
pMem->n = 2;
|
||||
sqlite3_snprintf(3, pMem->z, "%.2x", pOp->p5); /* P5 */
|
||||
pMem->type = SQLITE_TEXT;
|
||||
pMem->memType = MEM_Str;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
pMem++;
|
||||
|
||||
@ -1427,11 +1427,11 @@ int sqlite3VdbeList(
|
||||
}
|
||||
pMem->flags = MEM_Dyn|MEM_Str|MEM_Term;
|
||||
pMem->n = displayComment(pOp, zP4, pMem->z, 500);
|
||||
pMem->type = SQLITE_TEXT;
|
||||
pMem->memType = MEM_Str;
|
||||
pMem->enc = SQLITE_UTF8;
|
||||
#else
|
||||
pMem->flags = MEM_Null; /* Comment */
|
||||
pMem->type = SQLITE_NULL;
|
||||
pMem->memType = MEM_Null;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ void sqlite3VdbeMemReleaseExternal(Mem *p){
|
||||
/*
|
||||
** Release any memory held by the Mem. This may leave the Mem in an
|
||||
** inconsistent state, for example with (Mem.z==0) and
|
||||
** (Mem.type==SQLITE_TEXT).
|
||||
** (Mem.memType==MEM_Str).
|
||||
*/
|
||||
void sqlite3VdbeMemRelease(Mem *p){
|
||||
VdbeMemRelease(p);
|
||||
@ -480,7 +480,7 @@ void sqlite3VdbeMemSetNull(Mem *pMem){
|
||||
sqlite3RowSetClear(pMem->u.pRowSet);
|
||||
}
|
||||
MemSetTypeFlag(pMem, MEM_Null);
|
||||
pMem->type = SQLITE_NULL;
|
||||
pMem->memType = MEM_Null;
|
||||
}
|
||||
void sqlite3ValueSetNull(sqlite3_value *p){
|
||||
sqlite3VdbeMemSetNull((Mem*)p);
|
||||
@ -493,7 +493,7 @@ void sqlite3ValueSetNull(sqlite3_value *p){
|
||||
void sqlite3VdbeMemSetZeroBlob(Mem *pMem, int n){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->flags = MEM_Blob|MEM_Zero;
|
||||
pMem->type = SQLITE_BLOB;
|
||||
pMem->memType = MEM_Blob;
|
||||
pMem->n = 0;
|
||||
if( n<0 ) n = 0;
|
||||
pMem->u.nZero = n;
|
||||
@ -516,7 +516,7 @@ void sqlite3VdbeMemSetInt64(Mem *pMem, i64 val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->u.i = val;
|
||||
pMem->flags = MEM_Int;
|
||||
pMem->type = SQLITE_INTEGER;
|
||||
pMem->memType = MEM_Int;
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_FLOATING_POINT
|
||||
@ -531,7 +531,7 @@ void sqlite3VdbeMemSetDouble(Mem *pMem, double val){
|
||||
sqlite3VdbeMemRelease(pMem);
|
||||
pMem->r = val;
|
||||
pMem->flags = MEM_Real;
|
||||
pMem->type = SQLITE_FLOAT;
|
||||
pMem->memType = MEM_Real;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@ -739,7 +739,7 @@ int sqlite3VdbeMemSetStr(
|
||||
pMem->n = nByte;
|
||||
pMem->flags = flags;
|
||||
pMem->enc = (enc==0 ? SQLITE_UTF8 : enc);
|
||||
pMem->type = (enc==0 ? SQLITE_BLOB : SQLITE_TEXT);
|
||||
pMem->memType = flags&0x1f;
|
||||
|
||||
#ifndef SQLITE_OMIT_UTF16
|
||||
if( pMem->enc!=SQLITE_UTF8 && sqlite3VdbeMemHandleBom(pMem) ){
|
||||
@ -910,7 +910,7 @@ int sqlite3VdbeMemFromBtree(
|
||||
}else if( SQLITE_OK==(rc = sqlite3VdbeMemGrow(pMem, amt+2, 0)) ){
|
||||
pMem->flags = MEM_Blob|MEM_Dyn|MEM_Term;
|
||||
pMem->enc = 0;
|
||||
pMem->type = SQLITE_BLOB;
|
||||
pMem->memType = MEM_Blob;
|
||||
if( key ){
|
||||
rc = sqlite3BtreeKey(pCur, offset, amt, pMem->z);
|
||||
}else{
|
||||
@ -980,7 +980,7 @@ sqlite3_value *sqlite3ValueNew(sqlite3 *db){
|
||||
Mem *p = sqlite3DbMallocZero(db, sizeof(*p));
|
||||
if( p ){
|
||||
p->flags = MEM_Null;
|
||||
p->type = SQLITE_NULL;
|
||||
p->memType = MEM_Null;
|
||||
p->db = db;
|
||||
}
|
||||
return p;
|
||||
@ -1030,7 +1030,7 @@ static sqlite3_value *valueNew(sqlite3 *db, struct ValueNewStat4Ctx *p){
|
||||
pRec->aMem = (Mem *)((u8*)pRec + ROUND8(sizeof(UnpackedRecord)));
|
||||
for(i=0; i<nCol; i++){
|
||||
pRec->aMem[i].flags = MEM_Null;
|
||||
pRec->aMem[i].type = SQLITE_NULL;
|
||||
pRec->aMem[i].memType = MEM_Null;
|
||||
pRec->aMem[i].db = db;
|
||||
}
|
||||
}else{
|
||||
@ -1103,7 +1103,7 @@ static int valueFromExpr(
|
||||
zVal = sqlite3MPrintf(db, "%s%s", zNeg, pExpr->u.zToken);
|
||||
if( zVal==0 ) goto no_mem;
|
||||
sqlite3ValueSetStr(pVal, -1, zVal, SQLITE_UTF8, SQLITE_DYNAMIC);
|
||||
if( op==TK_FLOAT ) pVal->type = SQLITE_FLOAT;
|
||||
if( op==TK_FLOAT ) pVal->memType = MEM_Real;
|
||||
}
|
||||
if( (op==TK_INTEGER || op==TK_FLOAT ) && affinity==SQLITE_AFF_NONE ){
|
||||
sqlite3ValueApplyAffinity(pVal, SQLITE_AFF_NUMERIC, SQLITE_UTF8);
|
||||
|
Loading…
Reference in New Issue
Block a user