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

Performance improvement in sqlite3StrAccumFinish() for the common case where

no memory allocation is required.

FossilOrigin-Name: b6acf5d4ef016326a079463e70e71c2fc95a352d
This commit is contained in:
drh
2016-11-25 15:11:26 +00:00
parent 36fd41e52b
commit 043e586e29
3 changed files with 19 additions and 14 deletions

View File

@@ -861,18 +861,23 @@ void sqlite3StrAccumAppendAll(StrAccum *p, const char *z){
** Return a pointer to the resulting string. Return a NULL
** pointer if any kind of error was encountered.
*/
static SQLITE_NOINLINE char *strAccumFinishRealloc(StrAccum *p){
assert( p->mxAlloc>0 && !isMalloced(p) );
p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
if( p->zText ){
memcpy(p->zText, p->zBase, p->nChar+1);
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
}else{
setStrAccumError(p, STRACCUM_NOMEM);
}
return p->zText;
}
char *sqlite3StrAccumFinish(StrAccum *p){
if( p->zText ){
assert( (p->zText==p->zBase)==!isMalloced(p) );
p->zText[p->nChar] = 0;
if( p->mxAlloc>0 && !isMalloced(p) ){
p->zText = sqlite3DbMallocRaw(p->db, p->nChar+1 );
if( p->zText ){
memcpy(p->zText, p->zBase, p->nChar+1);
p->printfFlags |= SQLITE_PRINTF_MALLOCED;
}else{
setStrAccumError(p, STRACCUM_NOMEM);
}
return strAccumFinishRealloc(p);
}
}
return p->zText;