mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-12 13:01:09 +03:00
Streamline the processing of the AND operator. Slightly smaller and faster.
FossilOrigin-Name: 7713996aa99ce6dd35b5a2db74dd26658fb8d9817169b2a7531cdef6edb41403
This commit is contained in:
31
src/expr.c
31
src/expr.c
@@ -850,20 +850,16 @@ Expr *sqlite3PExpr(
|
||||
Expr *pRight /* Right operand */
|
||||
){
|
||||
Expr *p;
|
||||
if( op==TK_AND && pParse->nErr==0 && !IN_RENAME_OBJECT ){
|
||||
/* Take advantage of short-circuit false optimization for AND */
|
||||
p = sqlite3ExprAnd(pParse->db, pLeft, pRight);
|
||||
}else{
|
||||
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
|
||||
if( p ){
|
||||
memset(p, 0, sizeof(Expr));
|
||||
p->op = op & 0xff;
|
||||
p->iAgg = -1;
|
||||
}
|
||||
p = sqlite3DbMallocRawNN(pParse->db, sizeof(Expr));
|
||||
if( p ){
|
||||
memset(p, 0, sizeof(Expr));
|
||||
p->op = op & 0xff;
|
||||
p->iAgg = -1;
|
||||
sqlite3ExprAttachSubtrees(pParse->db, p, pLeft, pRight);
|
||||
}
|
||||
if( p ) {
|
||||
sqlite3ExprCheckHeight(pParse, p->nHeight);
|
||||
}else{
|
||||
sqlite3ExprDelete(pParse->db, pLeft);
|
||||
sqlite3ExprDelete(pParse->db, pRight);
|
||||
}
|
||||
return p;
|
||||
}
|
||||
@@ -919,19 +915,20 @@ static int exprAlwaysFalse(Expr *p){
|
||||
** of returning an AND expression, just return a constant expression with
|
||||
** a value of false.
|
||||
*/
|
||||
Expr *sqlite3ExprAnd(sqlite3 *db, Expr *pLeft, Expr *pRight){
|
||||
if( pLeft==0 ){
|
||||
Expr *sqlite3ExprAnd(Parse *pParse, Expr *pLeft, Expr *pRight){
|
||||
sqlite3 *db = pParse->db;
|
||||
if( pLeft==0 ){
|
||||
return pRight;
|
||||
}else if( pRight==0 ){
|
||||
return pLeft;
|
||||
}else if( pParse->nErr || IN_RENAME_OBJECT ){
|
||||
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
|
||||
}else if( exprAlwaysFalse(pLeft) || exprAlwaysFalse(pRight) ){
|
||||
sqlite3ExprDelete(db, pLeft);
|
||||
sqlite3ExprDelete(db, pRight);
|
||||
return sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[0], 0);
|
||||
}else{
|
||||
Expr *pNew = sqlite3ExprAlloc(db, TK_AND, 0, 0);
|
||||
sqlite3ExprAttachSubtrees(db, pNew, pLeft, pRight);
|
||||
return pNew;
|
||||
return sqlite3PExpr(pParse, TK_AND, pLeft, pRight);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user