From: drh Date: Wed, 21 Aug 2013 21:12:10 +0000 (+0000) Subject: Simplification to the StrAccum object and the sqlite3StrAccumAppend() X-Git-Tag: version-3.8.0~8 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b49bc86a1a6134806dde81bb788fcf4a9fa8d7a9;p=thirdparty%2Fsqlite.git Simplification to the StrAccum object and the sqlite3StrAccumAppend() method that also results in slightly better performance. FossilOrigin-Name: 700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a --- diff --git a/manifest b/manifest index cabb3227c3..c036908051 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Minor\sfixes\sfor\stest\scases.\sNo\scode\schanges. -D 2013-08-21T20:04:54.847 +C Simplification\sto\sthe\sStrAccum\sobject\sand\sthe\ssqlite3StrAccumAppend()\nmethod\sthat\salso\sresults\sin\sslightly\sbetter\sperformance. +D 2013-08-21T21:12:10.959 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 5e41da95d92656a5004b03d3576e8b226858a28e F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -163,7 +163,7 @@ F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34 F src/backup.c 43b348822db3e4cef48b2ae5a445fbeb6c73a165 F src/bitvec.c 19a4ba637bd85f8f63fc8c9bae5ade9fb05ec1cb F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 -F src/btree.c d49f16006152a2f2737b6a904287797724dbd760 +F src/btree.c 7e7b3eba8d902217fb2dbad0ac8217e952dba8ca F src/btree.h bfe0e8c5759b4ec77b0d18390064a6ef3cdffaaf F src/btreeInt.h 51cf220a9b9223354770883e93a859dc377aa27f F src/build.c f99a715ff9290996b579d5e1ec8e94239dc9ae5e @@ -175,7 +175,7 @@ F src/delete.c 2317c814866d9aa71fea16b3faf4fdd4d6a49b94 F src/expr.c 6bab61c757c4c4c94a92e98d507025d5d18afd3c F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 914a6bbd987d857c41ac9d244efa6641f36faadb -F src/func.c 5c50c1ea31fd864b0fe921fe1a8d4c55acd609ef +F src/func.c d7be77897c91d5b9887beb372f1e6deb515c92af F src/global.c 5caf4deab621abb45b4c607aad1bd21c20aac759 F src/hash.c ac3470bbf1ca4ae4e306a8ecb0fdf1731810ffe4 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22 @@ -212,7 +212,7 @@ F src/pcache.h a5e4f5d9f5d592051d91212c5949517971ae6222 F src/pcache1.c a467393909a4ed7ca9de066d85ba5c5b04a5be63 F src/pragma.c 1d96ba749253b49bc229c6294f9c2e5ef3dca85c F src/prepare.c fa6988589f39af8504a61731614cd4f6ae71554f -F src/printf.c 41c49dac366a3a411190001a8ab495fa8887974e +F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50 F src/resolve.c 9d53899cc6e1f4ec0b4632d07e97d57827bf63b9 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 @@ -221,7 +221,7 @@ F src/shell.c 1c317a4c96d61d8d9fdad9fd1811d9b10b8c7f57 F src/sqlite.h.in bd1451ba1ab681022a53bccc3c39580ba094a3ff F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc -F src/sqliteInt.h e4ae9edb97983a8d7d751559391962cf7668948c +F src/sqliteInt.h 124e4b19cd5533116909ccf203bdcdd04a28f99a F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 7ac05a5c7017d0b9f0b4bcd701228b784f987158 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -1105,7 +1105,7 @@ F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/wherecosttest.c f407dc4c79786982a475261866a161cd007947ae F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P f9859fe93bcecb4be7c1034291018523124c4a5c -R ddee5479b507575b9f0433a0c601d21b -U dan -Z 54b08646e994fdf84c4fc6867487aa5d +P ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db +R b5f522403c7336cdf922a181f76ebfed +U drh +Z 3ab1c9a1ca4e97a25908645404ada3f7 diff --git a/manifest.uuid b/manifest.uuid index def9fd1722..261a986cf4 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ef2a6a37366f91889dc2f1ba9cb6d1257d9b05db \ No newline at end of file +700dbbea8647e0fdaee6d0aba3d3dd8ebfbac04a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 44c35e6415..3fcce0dd46 100644 --- a/src/btree.c +++ b/src/btree.c @@ -7747,7 +7747,7 @@ static void checkAppendMsg( } sqlite3VXPrintf(&pCheck->errMsg, 1, zFormat, ap); va_end(ap); - if( pCheck->errMsg.mallocFailed ){ + if( pCheck->errMsg.accError==STRACCUM_NOMEM ){ pCheck->mallocFailed = 1; } } diff --git a/src/func.c b/src/func.c index 49f6c892be..be6e238670 100644 --- a/src/func.c +++ b/src/func.c @@ -1522,9 +1522,9 @@ static void groupConcatFinalize(sqlite3_context *context){ StrAccum *pAccum; pAccum = sqlite3_aggregate_context(context, 0); if( pAccum ){ - if( pAccum->tooBig ){ + if( pAccum->accError==STRACCUM_TOOBIG ){ sqlite3_result_error_toobig(context); - }else if( pAccum->mallocFailed ){ + }else if( pAccum->accError==STRACCUM_NOMEM ){ sqlite3_result_error_nomem(context); }else{ sqlite3_result_text(context, sqlite3StrAccumFinish(pAccum), -1, diff --git a/src/printf.c b/src/printf.c index 67649b269b..f9e5c6406d 100644 --- a/src/printf.c +++ b/src/printf.c @@ -359,7 +359,7 @@ void sqlite3VXPrintf( nOut = precision + 10; zOut = zExtra = sqlite3Malloc( nOut ); if( zOut==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } } @@ -471,7 +471,7 @@ void sqlite3VXPrintf( if( MAX(e2,0)+precision+width > etBUFSIZE - 15 ){ bufpt = zExtra = sqlite3Malloc( MAX(e2,0)+precision+width+15 ); if( bufpt==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } } @@ -606,7 +606,7 @@ void sqlite3VXPrintf( if( n>etBUFSIZE ){ bufpt = zExtra = sqlite3Malloc( n ); if( bufpt==0 ){ - pAccum->mallocFailed = 1; + pAccum->accError = STRACCUM_NOMEM; return; } }else{ @@ -684,22 +684,20 @@ void sqlite3VXPrintf( */ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ assert( z!=0 || N==0 ); - if( p->tooBig | p->mallocFailed ){ - testcase(p->tooBig); - testcase(p->mallocFailed); + if( p->accError ){ + testcase(p->accError==STRACCUM_TOOBIG); + testcase(p->accError==STRACCUM_NOMEM); return; } assert( p->zText!=0 || p->nChar==0 ); - if( N<0 ){ + if( N<=0 ){ + if( N==0 || z[0]==0 ) return; N = sqlite3Strlen30(z); } - if( N==0 || NEVER(z==0) ){ - return; - } if( p->nChar+N >= p->nAlloc ){ char *zNew; if( !p->useMalloc ){ - p->tooBig = 1; + p->accError = STRACCUM_TOOBIG; N = p->nAlloc - p->nChar - 1; if( N<=0 ){ return; @@ -710,7 +708,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ szNew += N + 1; if( szNew > p->mxAlloc ){ sqlite3StrAccumReset(p); - p->tooBig = 1; + p->accError = STRACCUM_TOOBIG; return; }else{ p->nAlloc = (int)szNew; @@ -724,7 +722,7 @@ void sqlite3StrAccumAppend(StrAccum *p, const char *z, int N){ if( zOld==0 && p->nChar>0 ) memcpy(zNew, p->zText, p->nChar); p->zText = zNew; }else{ - p->mallocFailed = 1; + p->accError = STRACCUM_NOMEM; sqlite3StrAccumReset(p); return; } @@ -752,7 +750,7 @@ char *sqlite3StrAccumFinish(StrAccum *p){ if( p->zText ){ memcpy(p->zText, p->zBase, p->nChar+1); }else{ - p->mallocFailed = 1; + p->accError = STRACCUM_NOMEM; } } } @@ -783,8 +781,7 @@ void sqlite3StrAccumInit(StrAccum *p, char *zBase, int n, int mx){ p->nAlloc = n; p->mxAlloc = mx; p->useMalloc = 1; - p->tooBig = 0; - p->mallocFailed = 0; + p->accError = 0; } /* @@ -801,7 +798,7 @@ char *sqlite3VMPrintf(sqlite3 *db, const char *zFormat, va_list ap){ acc.db = db; sqlite3VXPrintf(&acc, 1, zFormat, ap); z = sqlite3StrAccumFinish(&acc); - if( acc.mallocFailed ){ + if( acc.accError==STRACCUM_NOMEM ){ db->mallocFailed = 1; } return z; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index bde4008016..025bb466d5 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2425,10 +2425,11 @@ struct StrAccum { int nChar; /* Length of the string so far */ int nAlloc; /* Amount of space allocated in zText */ int mxAlloc; /* Maximum allowed string length */ - u8 mallocFailed; /* Becomes true if any memory allocation fails */ u8 useMalloc; /* 0: none, 1: sqlite3DbMalloc, 2: sqlite3_malloc */ - u8 tooBig; /* Becomes true if string size exceeds limits */ + u8 accError; /* STRACCUM_NOMEM or STRACCUM_TOOBIG */ }; +#define STRACCUM_NOMEM 1 +#define STRACCUM_TOOBIG 2 /* ** A pointer to this structure is used to communicate information