aboutsummaryrefslogtreecommitdiff
path: root/src/expr.c
diff options
context:
space:
mode:
authordrh <>2023-10-20 18:09:08 +0000
committerdrh <>2023-10-20 18:09:08 +0000
commite98f62fb3f23bc3e92796fe175c383177f0ef4ac (patch)
tree8b6fb34cf99e5291c4a875a85a808fb2128ec8d2 /src/expr.c
parentab3eb5b770841fe31428d74ceaf6d20ace405f7e (diff)
downloadsqlite-e98f62fb3f23bc3e92796fe175c383177f0ef4ac.tar.gz
sqlite-e98f62fb3f23bc3e92796fe175c383177f0ef4ac.zip
Omit some redundant calls to strlen() used to find the size of
Expr.u.zToken in sqliteExprDup(). This inefficiency was seen while working on the previous check-in, and I thought it best to fix it while it was fresh in mind. FossilOrigin-Name: b7a84eff5dcdf5b2ff81331097cdc64d0c5d16a4ae224320f39b64541ec72dc7
Diffstat (limited to 'src/expr.c')
-rw-r--r--src/expr.c26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/expr.c b/src/expr.c
index c47f7964a..73ff55373 100644
--- a/src/expr.c
+++ b/src/expr.c
@@ -1578,6 +1578,7 @@ static Expr *exprDup(
Expr *pNew; /* Value to return */
EdupBuf sEdupBuf; /* Memory space from which to build Expr object */
u32 staticFlag; /* EP_Static if space not obtained from malloc */
+ int nToken = -1; /* Space needed for p->u.zToken. -1 means unknown */
assert( db!=0 );
assert( p );
@@ -1594,7 +1595,16 @@ static Expr *exprDup(
assert( sEdupBuf.zAlloc!=0 );
assert( dupFlags==EXPRDUP_REDUCE );
}else{
- int nAlloc = dupFlags ? dupedExprSize(p) : dupedExprNodeSize(p, 0);
+ int nAlloc;
+ if( dupFlags ){
+ nAlloc = dupedExprSize(p);
+ }else if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
+ nToken = sqlite3Strlen30NN(p->u.zToken)+1;
+ nAlloc = EXPR_FULLSIZE + nToken;
+ }else{
+ nToken = 0;
+ nAlloc = EXPR_FULLSIZE;
+ }
sEdupBuf.zAlloc = sqlite3DbMallocRawNN(db, nAlloc);
#ifdef SQLITE_DEBUG
sEdupBuf.zEnd = sEdupBuf.zAlloc ? sEdupBuf.zAlloc+nAlloc : 0;
@@ -1612,11 +1622,12 @@ static Expr *exprDup(
*/
const unsigned nStructSize = dupedExprStructSize(p, dupFlags);
const int nNewSize = nStructSize & 0xfff;
- int nToken;
- if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
- nToken = sqlite3Strlen30(p->u.zToken) + 1;
- }else{
- nToken = 0;
+ if( nToken<0 ){
+ if( !ExprHasProperty(p, EP_IntValue) && p->u.zToken ){
+ nToken = sqlite3Strlen30(p->u.zToken) + 1;
+ }else{
+ nToken = 0;
+ }
}
if( dupFlags ){
assert( (int)(sEdupBuf.zEnd - sEdupBuf.zAlloc) >= nNewSize+nToken );
@@ -1643,7 +1654,8 @@ static Expr *exprDup(
}
/* Copy the p->u.zToken string, if any. */
- if( nToken ){
+ assert( nToken>=0 );
+ if( nToken>0 ){
char *zToken = pNew->u.zToken = (char*)sEdupBuf.zAlloc;
memcpy(zToken, p->u.zToken, nToken);
sEdupBuf.zAlloc += nToken;