diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/btree.c | 16 | ||||
-rw-r--r-- | src/btree.h | 1 | ||||
-rw-r--r-- | src/vdbe.c | 3 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/btree.c b/src/btree.c index cbf93d222..c02f070e0 100644 --- a/src/btree.c +++ b/src/btree.c @@ -3278,8 +3278,8 @@ int sqlite3BtreeSavepoint(Btree *p, int op, int iSavepoint){ ** root page of a b-tree. If it is not, then the cursor acquired ** will not work correctly. ** -** It is assumed that the sqlite3BtreeCursorSize() bytes of memory -** pointed to by pCur have been zeroed by the caller. +** It is assumed that the sqlite3BtreeCursorZero() has been called +** on pCur to initialize the memory space prior to invoking this routine. */ static int btreeCursor( Btree *p, /* The btree */ @@ -3356,6 +3356,18 @@ int sqlite3BtreeCursorSize(void){ } /* +** Initialize memory that will be converted into a BtCursor object. +** +** The simple approach here would be to memset() the entire object +** to zero. But it turns out that the apPage[] and aiIdx[] arrays +** do not need to be zeroed and they are large, so we can save a lot +** of run-time by skipping the initialization of those elements. +*/ +void sqlite3BtreeCursorZero(BtCursor *p){ + memset(p, 0, offsetof(BtCursor, iPage)); +} + +/* ** Set the cached rowid value of every cursor in the same database file ** as pCur and having the same root page number as pCur. The value is ** set to iRowid. diff --git a/src/btree.h b/src/btree.h index 93de4d1c3..7852d4ae6 100644 --- a/src/btree.h +++ b/src/btree.h @@ -148,6 +148,7 @@ int sqlite3BtreeCursor( BtCursor *pCursor /* Space to write cursor structure */ ); int sqlite3BtreeCursorSize(void); +void sqlite3BtreeCursorZero(BtCursor*); int sqlite3BtreeCloseCursor(BtCursor*); int sqlite3BtreeMovetoUnpacked( diff --git a/src/vdbe.c b/src/vdbe.c index 4ea20b752..90dd90e67 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -215,7 +215,7 @@ static VdbeCursor *allocateCursor( } if( SQLITE_OK==sqlite3VdbeMemGrow(pMem, nByte, 0) ){ p->apCsr[iCur] = pCx = (VdbeCursor*)pMem->z; - memset(pCx, 0, nByte); + memset(pCx, 0, sizeof(VdbeCursor)); pCx->iDb = iDb; pCx->nField = nField; if( nField ){ @@ -224,6 +224,7 @@ static VdbeCursor *allocateCursor( if( isBtreeCursor ){ pCx->pCursor = (BtCursor*) &pMem->z[ROUND8(sizeof(VdbeCursor))+2*nField*sizeof(u32)]; + sqlite3BtreeCursorZero(pCx->pCursor); } } return pCx; |