1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-09 14:21:03 +03:00

Minor coding enhancements. (CVS 1839)

FossilOrigin-Name: 65c3af74c16c9fe0341b1e7e6d029927503f7404
This commit is contained in:
drh
2004-07-21 02:53:29 +00:00
parent 193bd777aa
commit 17c402944a
4 changed files with 68 additions and 123 deletions

View File

@@ -1,5 +1,5 @@
C Simplify\sthe\swhere.c\slogic\sby\sflipping\sexpression\sover\sso\sthat\sthe\scontrolling\nvariable\sis\salways\son\sthe\sleft.\s(CVS\s1838) C Minor\scoding\senhancements.\s(CVS\s1839)
D 2004-07-20T18:23:15 D 2004-07-21T02:53:30
F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b F Makefile.in 4a5e570a9e2d35b09c31b3cf01b78cea764ade4b
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457 F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -33,7 +33,7 @@ F src/build.c a4b1e80b13c570c7c962f500fa58045450b5a0cd
F src/date.c e1bb384a7856c18dce9cadb0afbe6934ba5ddb00 F src/date.c e1bb384a7856c18dce9cadb0afbe6934ba5ddb00
F src/delete.c e81545e546f6bc87d7508a93a09ca70695265af3 F src/delete.c e81545e546f6bc87d7508a93a09ca70695265af3
F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37 F src/encode.c a876af473d1d636faa3dca51c7571f2e007eea37
F src/expr.c df21bde644eca66276eafe0c97734fc8f930f4ab F src/expr.c a4e8ac69c872f86bc207364be0e32d0638f61e90
F src/func.c b163fb49efec999eb7bf982f7de5b9be388301f3 F src/func.c b163fb49efec999eb7bf982f7de5b9be388301f3
F src/hash.c f0a2f22c2a7052d67053b5f4690ea3010bb3fb9f F src/hash.c f0a2f22c2a7052d67053b5f4690ea3010bb3fb9f
F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb F src/hash.h 762d95f1e567664d1eafc1687de755626be962fb
@@ -74,7 +74,7 @@ F src/update.c b66b1896c9da54678ba3eff2bf0b4d291a95986a
F src/utf.c f03535db72bfa09e24202ccdd245f21d2fc65f0a F src/utf.c f03535db72bfa09e24202ccdd245f21d2fc65f0a
F src/util.c 2aacc79b7bf5df5859813dafd3bf3258f67a5234 F src/util.c 2aacc79b7bf5df5859813dafd3bf3258f67a5234
F src/vacuum.c b8546f4921719458cc537b9e736df52a8256399c F src/vacuum.c b8546f4921719458cc537b9e736df52a8256399c
F src/vdbe.c a88514694be86eca792dd4d291e766f3c1831876 F src/vdbe.c 5a7d1ee9d7356df6b53be64c1776824a33f6f2fb
F src/vdbe.h 75b241c02431b9c0f16eaa9cdbb34146c6287f52 F src/vdbe.h 75b241c02431b9c0f16eaa9cdbb34146c6287f52
F src/vdbeInt.h 7160653a006b6d2c4a00d204112a095bdf842ab6 F src/vdbeInt.h 7160653a006b6d2c4a00d204112a095bdf842ab6
F src/vdbeapi.c c5c6d8f162a9581dde497b1a4034f9a0bf54c355 F src/vdbeapi.c c5c6d8f162a9581dde497b1a4034f9a0bf54c355
@@ -237,7 +237,7 @@ F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0 F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
P 3c5aa850eeec5c75c5200a3707852cc5fc9e780b P ec8bfa3891dbf0f3172e31cf322974c03f9af59a
R 85614d781cba6751b913b133092132cd R 9e5a169fd77b5347506f033f7c0bac3e
U drh U drh
Z 550b1f0e24b844483d3dbfa3a8f89d17 Z 16e953d85e2aa59a57853642a9ecf96b

View File

@@ -1 +1 @@
ec8bfa3891dbf0f3172e31cf322974c03f9af59a 65c3af74c16c9fe0341b1e7e6d029927503f7404

View File

@@ -12,7 +12,7 @@
** This file contains routines used for analyzing expressions and ** This file contains routines used for analyzing expressions and
** for generating VDBE code that evaluates expressions in SQLite. ** for generating VDBE code that evaluates expressions in SQLite.
** **
** $Id: expr.c,v 1.151 2004/07/19 00:39:45 drh Exp $ ** $Id: expr.c,v 1.152 2004/07/21 02:53:30 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include <ctype.h> #include <ctype.h>
@@ -1167,16 +1167,11 @@ void sqlite3ExprCode(Parse *pParse, Expr *pExpr){
case TK_REM: case TK_REM:
case TK_BITAND: case TK_BITAND:
case TK_BITOR: case TK_BITOR:
case TK_SLASH: { case TK_SLASH:
sqlite3ExprCode(pParse, pExpr->pLeft);
sqlite3ExprCode(pParse, pExpr->pRight);
sqlite3VdbeAddOp(v, op, 0, 0);
break;
}
case TK_LSHIFT: case TK_LSHIFT:
case TK_RSHIFT: { case TK_RSHIFT: {
sqlite3ExprCode(pParse, pExpr->pRight);
sqlite3ExprCode(pParse, pExpr->pLeft); sqlite3ExprCode(pParse, pExpr->pLeft);
sqlite3ExprCode(pParse, pExpr->pRight);
sqlite3VdbeAddOp(v, op, 0, 0); sqlite3VdbeAddOp(v, op, 0, 0);
break; break;
} }

View File

@@ -43,7 +43,7 @@
** in this file for details. If in doubt, do not deviate from existing ** in this file for details. If in doubt, do not deviate from existing
** commenting and indentation practices when changing or adding code. ** commenting and indentation practices when changing or adding code.
** **
** $Id: vdbe.c,v 1.402 2004/07/19 17:25:25 drh Exp $ ** $Id: vdbe.c,v 1.403 2004/07/21 02:53:30 drh Exp $
*/ */
#include "sqliteInt.h" #include "sqliteInt.h"
#include "os.h" #include "os.h"
@@ -290,54 +290,43 @@ static Cursor *allocateCursor(Vdbe *p, int iCur){
** **
*/ */
static void applyAffinity(Mem *pRec, char affinity, u8 enc){ static void applyAffinity(Mem *pRec, char affinity, u8 enc){
switch( affinity ){ if( affinity==SQLITE_AFF_NONE ){
case SQLITE_AFF_INTEGER: /* do nothing */
case SQLITE_AFF_NUMERIC: }else if( affinity==SQLITE_AFF_TEXT ){
if( 0==(pRec->flags&(MEM_Real|MEM_Int)) ){ /* Only attempt the conversion to TEXT if there is an integer or real
/* pRec does not have a valid integer or real representation. ** representation (blob and NULL do not get converted) but no string
** Attempt a conversion if pRec has a string representation and ** representation.
** it looks like a number. */
*/ if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){
int realnum; sqlite3VdbeMemStringify(pRec, enc);
sqlite3VdbeMemNulTerminate(pRec); }
if( pRec->flags&MEM_Str && sqlite3IsNumber(pRec->z, &realnum, enc) ){ pRec->flags &= ~(MEM_Real|MEM_Int);
if( realnum ){ }else{
Realify(pRec); if( 0==(pRec->flags&(MEM_Real|MEM_Int)) ){
}else{ /* pRec does not have a valid integer or real representation.
Integerify(pRec); ** Attempt a conversion if pRec has a string representation and
} ** it looks like a number.
}
}
if( affinity==SQLITE_AFF_INTEGER ){
/* For INTEGER affinity, try to convert a real value to an int */
if( (pRec->flags&MEM_Real) && !(pRec->flags&MEM_Int) ){
pRec->i = pRec->r;
if( ((double)pRec->i)==pRec->r ){
pRec->flags |= MEM_Int;
}
}
}
break;
case SQLITE_AFF_TEXT:
/* Only attempt the conversion if there is an integer or real
** representation (blob and NULL do not get converted) but no string
** representation.
*/ */
if( 0==(pRec->flags&MEM_Str) && (pRec->flags&(MEM_Real|MEM_Int)) ){ int realnum;
sqlite3VdbeMemStringify(pRec, enc); sqlite3VdbeMemNulTerminate(pRec);
if( pRec->flags&MEM_Str && sqlite3IsNumber(pRec->z, &realnum, enc) ){
if( realnum ){
Realify(pRec);
}else{
Integerify(pRec);
}
} }
pRec->flags &= ~(MEM_Real|MEM_Int); }
break; if( affinity==SQLITE_AFF_INTEGER ){
/* For INTEGER affinity, try to convert a real value to an int */
case SQLITE_AFF_NONE: if( (pRec->flags&MEM_Real) && !(pRec->flags&MEM_Int) ){
/* Affinity NONE. Do nothing. */ pRec->i = pRec->r;
break; if( ((double)pRec->i)==pRec->r ){
pRec->flags |= MEM_Int;
default: }
assert(0); }
}
} }
} }
@@ -608,11 +597,7 @@ case OP_Goto: {
** with a fatal error. ** with a fatal error.
*/ */
case OP_Gosub: { case OP_Gosub: {
if( p->returnDepth>=sizeof(p->returnStack)/sizeof(p->returnStack[0]) ){ assert( p->returnDepth<sizeof(p->returnStack)/sizeof(p->returnStack[0]) );
sqlite3SetString(&p->zErrMsg, "return address stack overflow", (char*)0);
p->rc = SQLITE_INTERNAL;
return SQLITE_ERROR;
}
p->returnStack[p->returnDepth++] = pc+1; p->returnStack[p->returnDepth++] = pc+1;
pc = pOp->p2 - 1; pc = pOp->p2 - 1;
break; break;
@@ -625,11 +610,7 @@ case OP_Gosub: {
** processing aborts with a fatal error. ** processing aborts with a fatal error.
*/ */
case OP_Return: { case OP_Return: {
if( p->returnDepth<=0 ){ assert( p->returnDepth>0 );
sqlite3SetString(&p->zErrMsg, "return address stack underflow", (char*)0);
p->rc = SQLITE_INTERNAL;
return SQLITE_ERROR;
}
p->returnDepth--; p->returnDepth--;
pc = p->returnStack[p->returnDepth] - 1; pc = p->returnStack[p->returnDepth] - 1;
break; break;
@@ -658,9 +639,7 @@ case OP_Halt: {
if( pOp->p1!=SQLITE_OK ){ if( pOp->p1!=SQLITE_OK ){
p->rc = pOp->p1; p->rc = pOp->p1;
p->errorAction = pOp->p2; p->errorAction = pOp->p2;
if( pOp->p3 ){ sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0);
sqlite3SetString(&p->zErrMsg, pOp->p3, (char*)0);
}
return SQLITE_ERROR; return SQLITE_ERROR;
}else{ }else{
p->rc = SQLITE_OK; p->rc = SQLITE_OK;
@@ -813,6 +792,7 @@ case OP_Variable: {
assert( j>=0 && j<p->nVar ); assert( j>=0 && j<p->nVar );
pTos++; pTos++;
/* sqlite3VdbeMemCopyStatic(pTos, &p->apVar[j]); */
memcpy(pTos, &p->apVar[j], sizeof(*pTos)-NBFS); memcpy(pTos, &p->apVar[j], sizeof(*pTos)-NBFS);
pTos->xDel = 0; pTos->xDel = 0;
if( pTos->flags&(MEM_Str|MEM_Blob) ){ if( pTos->flags&(MEM_Str|MEM_Blob) ){
@@ -1297,15 +1277,15 @@ case OP_Function: {
/* Opcode: ShiftLeft * * * /* Opcode: ShiftLeft * * *
** **
** Pop the top two elements from the stack. Convert both elements ** Pop the top two elements from the stack. Convert both elements
** to integers. Push back onto the stack the top element shifted ** to integers. Push back onto the stack the second element shifted
** left by N bits where N is the second element on the stack. ** left by N bits where N is the top element on the stack.
** If either operand is NULL, the result is NULL. ** If either operand is NULL, the result is NULL.
*/ */
/* Opcode: ShiftRight * * * /* Opcode: ShiftRight * * *
** **
** Pop the top two elements from the stack. Convert both elements ** Pop the top two elements from the stack. Convert both elements
** to integers. Push back onto the stack the top element shifted ** to integers. Push back onto the stack the second element shifted
** right by N bits where N is the second element on the stack. ** right by N bits where N is the top element on the stack.
** If either operand is NULL, the result is NULL. ** If either operand is NULL, the result is NULL.
*/ */
case OP_BitAnd: case OP_BitAnd:
@@ -1322,8 +1302,8 @@ case OP_ShiftRight: {
pTos->flags = MEM_Null; pTos->flags = MEM_Null;
break; break;
} }
a = sqlite3VdbeIntValue(pTos); a = sqlite3VdbeIntValue(pNos);
b = sqlite3VdbeIntValue(pNos); b = sqlite3VdbeIntValue(pTos);
switch( pOp->opcode ){ switch( pOp->opcode ){
case OP_BitAnd: a &= b; break; case OP_BitAnd: a &= b; break;
case OP_BitOr: a |= b; break; case OP_BitOr: a |= b; break;
@@ -1366,8 +1346,8 @@ case OP_AddImm: {
case OP_ForceInt: { case OP_ForceInt: {
int v; int v;
assert( pTos>=p->aStack ); assert( pTos>=p->aStack );
if( (pTos->flags & (MEM_Int|MEM_Real))==0 && ((pTos->flags & MEM_Str)==0 applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc);
|| sqlite3IsNumber(pTos->z, 0, db->enc)==0) ){ if( (pTos->flags & (MEM_Int|MEM_Real))==0 ){
Release(pTos); Release(pTos);
pTos--; pTos--;
pc = pOp->p2 - 1; pc = pOp->p2 - 1;
@@ -1400,48 +1380,18 @@ case OP_ForceInt: {
*/ */
case OP_MustBeInt: { case OP_MustBeInt: {
assert( pTos>=p->aStack ); assert( pTos>=p->aStack );
if( pTos->flags & MEM_Int ){ applyAffinity(pTos, SQLITE_AFF_INTEGER, db->enc);
/* Do nothing */ if( (pTos->flags & MEM_Int)==0 ){
}else if( pTos->flags & MEM_Real ){ if( pOp->p2==0 ){
int i = (int)pTos->r; rc = SQLITE_MISMATCH;
double r = (double)i; goto abort_due_to_error;
if( r!=pTos->r ){ }else{
goto mismatch; if( pOp->p1 ) popStack(&pTos, 1);
pc = pOp->p2 - 1;
} }
pTos->i = i;
}else if( pTos->flags & MEM_Str ){
i64 v;
if( sqlite3VdbeChangeEncoding(pTos, SQLITE_UTF8)
|| sqlite3VdbeMemNulTerminate(pTos) ){
goto no_mem;
}
if( !sqlite3atoi64(pTos->z, &v) ){
double r;
if( !sqlite3IsNumber(pTos->z, 0, SQLITE_UTF8) ){
goto mismatch;
}
Realify(pTos);
v = (int)pTos->r;
r = (double)v;
if( r!=pTos->r ){
goto mismatch;
}
}
pTos->i = v;
}else{ }else{
goto mismatch; Release(pTos);
} pTos->flags = MEM_Int;
Release(pTos);
pTos->flags = MEM_Int;
break;
mismatch:
if( pOp->p2==0 ){
rc = SQLITE_MISMATCH;
goto abort_due_to_error;
}else{
if( pOp->p1 ) popStack(&pTos, 1);
pc = pOp->p2 - 1;
} }
break; break;
} }