aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2018-12-28 20:48:07 +0000
committerdrh <drh@noemail.net>2018-12-28 20:48:07 +0000
commit81f9159b5ec0e19d9aafee9c03a13bc4e7735cd8 (patch)
tree77b01670a7bcc475650ad510d382ac883d77ae07 /src
parentb6991796b4b6f1a9c591349dd6d6ac4438f1db79 (diff)
downloadsqlite-81f9159b5ec0e19d9aafee9c03a13bc4e7735cd8.tar.gz
sqlite-81f9159b5ec0e19d9aafee9c03a13bc4e7735cd8.zip
Faster allocation of new sqlite3_stmt objects.
FossilOrigin-Name: 891f1f72187f0f9ec0d24fda98cc08be3ae3c3ff8b27c4e409ee7135c3106398
Diffstat (limited to 'src')
-rw-r--r--src/vdbeInt.h8
-rw-r--r--src/vdbeaux.c26
2 files changed, 21 insertions, 13 deletions
diff --git a/src/vdbeInt.h b/src/vdbeInt.h
index 1dc7f6613..acc7f5a6a 100644
--- a/src/vdbeInt.h
+++ b/src/vdbeInt.h
@@ -385,6 +385,10 @@ struct Vdbe {
i64 nFkConstraint; /* Number of imm. FK constraints this VM */
i64 nStmtDefCons; /* Number of def. constraints when stmt started */
i64 nStmtDefImmCons; /* Number of def. imm constraints when stmt started */
+ Mem *aMem; /* The memory locations */
+ Mem **apArg; /* Arguments to currently executing user function */
+ VdbeCursor **apCsr; /* One element of this array for each open cursor */
+ Mem *aVar; /* Values for the OP_Variable opcode. */
/* When allocating a new Vdbe object, all of the fields below should be
** initialized to zero or NULL */
@@ -392,13 +396,9 @@ struct Vdbe {
Op *aOp; /* Space to hold the virtual machine's program */
int nOp; /* Number of instructions in the program */
int nOpAlloc; /* Slots allocated for aOp[] */
- Mem *aMem; /* The memory locations */
- Mem **apArg; /* Arguments to currently executing user function */
Mem *aColName; /* Column names to return */
Mem *pResultSet; /* Pointer to an array of results */
char *zErrMsg; /* Error message written here */
- VdbeCursor **apCsr; /* One element of this array for each open cursor */
- Mem *aVar; /* Values for the OP_Variable opcode. */
VList *pVList; /* Name of variables */
#ifndef SQLITE_OMIT_TRACE
i64 startTime; /* Time when query started - used for profiling */
diff --git a/src/vdbeaux.c b/src/vdbeaux.c
index ada89ce90..bd1d18058 100644
--- a/src/vdbeaux.c
+++ b/src/vdbeaux.c
@@ -2187,19 +2187,27 @@ void sqlite3VdbeMakeReady(
** the leftover memory at the end of the opcode array. This can significantly
** reduce the amount of memory held by a prepared statement.
*/
- do {
- x.nNeeded = 0;
- p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
- p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
- p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
- p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
+ x.nNeeded = 0;
+ p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
+ p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
+ p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
+ p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
- p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
+ p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
#endif
- if( x.nNeeded==0 ) break;
+ if( x.nNeeded ){
x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
x.nFree = x.nNeeded;
- }while( !db->mallocFailed );
+ if( !db->mallocFailed ){
+ p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
+ p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
+ p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
+ p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
+ p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
+#endif
+ }
+ }
p->pVList = pParse->pVList;
pParse->pVList = 0;