diff options
author | drh <> | 2023-01-03 18:51:18 +0000 |
---|---|---|
committer | drh <> | 2023-01-03 18:51:18 +0000 |
commit | fbde3f50bfcb2235589a5c248a23b3990fd05d9f (patch) | |
tree | feb6dcd3e2065934d3dc6b1cb238fe469265d66e /src | |
parent | 1eb88d6e5a5bae41ab08df5949d82d816b3bb7d6 (diff) | |
download | sqlite-fbde3f50bfcb2235589a5c248a23b3990fd05d9f.tar.gz sqlite-fbde3f50bfcb2235589a5c248a23b3990fd05d9f.zip |
Avoid an unnecessary call to strlen() in the sqlite3VdbeMemStringify() routine,
for a performance increase and size reduction.
FossilOrigin-Name: 284382d37850f469dc4bf3ab8efd2f20971554e897f1ba3e94d3f2f0c35d97d0
Diffstat (limited to 'src')
-rw-r--r-- | src/sqliteInt.h | 2 | ||||
-rw-r--r-- | src/util.c | 8 | ||||
-rw-r--r-- | src/vdbemem.c | 11 |
3 files changed, 14 insertions, 7 deletions
diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 838c6e7b5..322cac1d6 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -5004,7 +5004,7 @@ int sqlite3FixExpr(DbFixer*, Expr*); int sqlite3FixTriggerStep(DbFixer*, TriggerStep*); int sqlite3RealSameAsInt(double,sqlite3_int64); i64 sqlite3RealToI64(double); -void sqlite3Int64ToText(i64,char*); +int sqlite3Int64ToText(i64,char*); int sqlite3AtoF(const char *z, double*, int, u8); int sqlite3GetInt32(const char *, int*); int sqlite3GetUInt32(const char*, u32*); diff --git a/src/util.c b/src/util.c index 72faafea5..23c6b1a66 100644 --- a/src/util.c +++ b/src/util.c @@ -632,11 +632,14 @@ do_atof_calc: #endif /* -** Render an signed 64-bit integer as text. Store the result in zOut[]. +** Render an signed 64-bit integer as text. Store the result in zOut[] and +** return the length of the string that was stored, in bytes. The value +** returned does not include the zero terminator at the end of the output +** string. ** ** The caller must ensure that zOut[] is at least 21 bytes in size. */ -void sqlite3Int64ToText(i64 v, char *zOut){ +int sqlite3Int64ToText(i64 v, char *zOut){ int i; u64 x; char zTemp[22]; @@ -653,6 +656,7 @@ void sqlite3Int64ToText(i64 v, char *zOut){ }while( x ); if( v<0 ) zTemp[i--] = '-'; memcpy(zOut, &zTemp[i+1], sizeof(zTemp)-1-i); + return sizeof(zTemp)-2-i; } /* diff --git a/src/vdbemem.c b/src/vdbemem.c index f14599def..11fadbb2b 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -114,9 +114,9 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){ i64 x; assert( (p->flags&MEM_Int)*2==sizeof(x) ); memcpy(&x, (char*)&p->u, (p->flags&MEM_Int)*2); - sqlite3Int64ToText(x, zBuf); + p->n = sqlite3Int64ToText(x, zBuf); #else - sqlite3Int64ToText(p->u.i, zBuf); + p->n = sqlite3Int64ToText(p->u.i, zBuf); #endif }else{ sqlite3StrAccumInit(&acc, 0, zBuf, sz, 0); @@ -124,6 +124,7 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){ (p->flags & MEM_IntReal)!=0 ? (double)p->u.i : p->u.r); assert( acc.zText==zBuf && acc.mxAlloc<=0 ); zBuf[acc.nChar] = 0; /* Fast version of sqlite3StrAccumFinish(&acc) */ + p->n = acc.nChar; } } @@ -151,6 +152,7 @@ static void vdbeMemRenderNum(int sz, char *zBuf, Mem *p){ ** This routine is for use inside of assert() statements only. */ int sqlite3VdbeMemValidStrRep(Mem *p){ + Mem tmp; char zBuf[100]; char *z; int i, j, incr; @@ -167,7 +169,8 @@ int sqlite3VdbeMemValidStrRep(Mem *p){ assert( p->enc==SQLITE_UTF8 || p->z[((p->n+1)&~1)+1]==0 ); } if( (p->flags & (MEM_Int|MEM_Real|MEM_IntReal))==0 ) return 1; - vdbeMemRenderNum(sizeof(zBuf), zBuf, p); + memcpy(&tmp, p, sizeof(tmp)); + vdbeMemRenderNum(sizeof(zBuf), zBuf, &tmp); z = p->z; i = j = 0; incr = 1; @@ -436,7 +439,7 @@ int sqlite3VdbeMemStringify(Mem *pMem, u8 enc, u8 bForce){ vdbeMemRenderNum(nByte, pMem->z, pMem); assert( pMem->z!=0 ); - pMem->n = sqlite3Strlen30NN(pMem->z); + assert( pMem->n==sqlite3Strlen30NN(pMem->z) ); pMem->enc = SQLITE_UTF8; pMem->flags |= MEM_Str|MEM_Term; if( bForce ) pMem->flags &= ~(MEM_Int|MEM_Real|MEM_IntReal); |