1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Minor modification to restoreOrClearCursorPosition() to improve efficiency. Do not allocate the extra 8-bytes if memory-management is not enabled. (CVS 2936)

FossilOrigin-Name: dd705955429d847af85ffaf248976bcd1d861852
This commit is contained in:
danielk1977
2006-01-13 06:33:23 +00:00
parent 777e4c43f2
commit e725929686
15 changed files with 79 additions and 54 deletions

View File

@@ -9,7 +9,7 @@
** May you share freely, never taking more than you give.
**
*************************************************************************
** $Id: btree.c,v 1.295 2006/01/13 04:31:58 drh Exp $
** $Id: btree.c,v 1.296 2006/01/13 06:33:24 danielk1977 Exp $
**
** This file implements a external (disk-based) database using BTrees.
** For a detailed discussion of BTrees, refer to
@@ -581,24 +581,26 @@ static int saveAllCursors(BtShared *pBt, Pgno iRoot, BtCursor *pExcept){
** returning the cursor to it's saved position, any saved position is deleted
** and the cursor state set to CURSOR_INVALID.
*/
static int restoreOrClearCursorPosition(BtCursor *pCur, int doSeek){
static int restoreOrClearCursorPositionX(BtCursor *pCur, int doSeek){
int rc = SQLITE_OK;
if( pCur->eState==CURSOR_REQUIRESEEK ){
assert( sqlite3ThreadDataReadOnly()->useSharedData );
if( doSeek ){
rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, &pCur->skip);
}else{
pCur->eState = CURSOR_INVALID;
}
if( rc==SQLITE_OK ){
sqliteFree(pCur->pKey);
pCur->pKey = 0;
assert( CURSOR_VALID==pCur->eState || CURSOR_INVALID==pCur->eState );
}
assert( sqlite3ThreadDataReadOnly()->useSharedData );
assert( pCur->eState==CURSOR_REQUIRESEEK );
if( doSeek ){
rc = sqlite3BtreeMoveto(pCur, pCur->pKey, pCur->nKey, &pCur->skip);
}else{
pCur->eState = CURSOR_INVALID;
}
if( rc==SQLITE_OK ){
sqliteFree(pCur->pKey);
pCur->pKey = 0;
assert( CURSOR_VALID==pCur->eState || CURSOR_INVALID==pCur->eState );
}
return rc;
}
#define restoreOrClearCursorPosition(p,x) \
(p->eState==CURSOR_REQUIRESEEK?restoreOrClearCursorPositionX(p,x):SQLITE_OK)
/*
** Query to see if btree handle p may obtain a lock of type eLock
** (READ_LOCK or WRITE_LOCK) on the table with root-page iTab. Return