From 1cc5ed815011e57e4da392759ae7150e644d30bf Mon Sep 17 00:00:00 2001 From: danielk1977 Date: Wed, 16 May 2007 17:28:43 +0000 Subject: [PATCH] Change a few selected functions to macros to speed things up. (CVS 4015) FossilOrigin-Name: 93f811ec747f6a42daf9ee27cd8b013f248552a1 --- manifest | 24 +++++++-------- manifest.uuid | 2 +- src/btree.c | 78 +++++++++++++++++++++++++++++-------------------- src/btreeInt.h | 6 ++-- src/malloc.c | 18 ++++-------- src/sqliteInt.h | 16 ++++++++-- src/util.c | 11 ++----- src/vdbe.c | 22 +++++++++----- src/vdbemem.c | 12 ++++++-- 9 files changed, 105 insertions(+), 84 deletions(-) diff --git a/manifest b/manifest index e7b44028f7..352e3de550 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Omit\ssome\sextra\scode\swhen\sOMIT_INCRBLOB\sis\sdefined.\s(CVS\s4014) -D 2007-05-16T14:23:00 +C Change\sa\sfew\sselected\sfunctions\sto\smacros\sto\sspeed\sthings\sup.\s(CVS\s4015) +D 2007-05-16T17:28:43 F Makefile.in 87b200ad9970907f76df734d29dff3d294c10935 F Makefile.linux-gcc 2d8574d1ba75f129aba2019f0b959db380a90935 F README 9c4e2d6706bdcc3efdd773ce752a8cdab4f90028 @@ -61,9 +61,9 @@ F src/alter.c 1b1deeb97446ed87f2fa17a3eb6236548841a348 F src/analyze.c e8fcb1c35ace8418615eb18d9601f321ac86b2ec F src/attach.c ba628db0c2b6a362f036d017bf1196cdfe4ebb37 F src/auth.c 5ea90bc93dfea46e9fe4bf531e14c7cd98219ecb -F src/btree.c 0c2f9b06c90d7c59925c03153c9d47fd739c8ca5 +F src/btree.c 911798b91bbad31a033ed501b95c76df8541874b F src/btree.h 1d527bf61ed176f980c34999d5793a0fd45dcf8c -F src/btreeInt.h 701343a0da648efb9591bb1f7b1a66199c270331 +F src/btreeInt.h f92c0577f49d961c0148b477a25647e8fd80eecf F src/build.c 50992d92e131a9aa9aa6657fb1ddc13e176fd70c F src/callback.c 9c12535669a638f90a67e10440b99c7b93c0fbf4 F src/complete.c 7d1a44be8f37de125fcafd3d3a018690b3799675 @@ -79,7 +79,7 @@ F src/legacy.c 388c71ad7fbcd898ba1bcbfc98a3ac954bfa5d01 F src/limits.h cf772eb244aae5859fa1554394866c27d3f3639c F src/loadext.c afe4f4755dc49c36ef505748bbdddecb9f1d02a2 F src/main.c 797dc983716c1480f6af78a36be3add8806211a1 -F src/malloc.c b89e31258a85158d15795bf87ae3ba007e56329b +F src/malloc.c 07790014b4b126016ce3c94885a215e45eb07ad5 F src/md5.c c5fdfa5c2593eaee2e32a5ce6c6927c986eaf217 F src/os.c 1f10b47acc1177fb9225edb4f5f0d25ed716f9cb F src/os.h 213dd1f8f7ab9159c04a893eadc0cdd52515df16 @@ -104,7 +104,7 @@ F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96 F src/shell.c d07ae326b3815d80f71c69b3c7584382e47f6447 F src/sqlite.h.in aa3c0c02883663944db09ee79f3165d3c4ad7c47 F src/sqlite3ext.h 7d0d363ea7327e817ef0dfe1b7eee1f171b72890 -F src/sqliteInt.h 0f3b39aebdb6d0490abafb48bec7047e799dfbfa +F src/sqliteInt.h 58edde37943f4f8155986f0c33735ba31fc66e9f F src/table.c a8de75bcedf84d4060d804264b067ab3b1a3561d F src/tclsqlite.c f425c7583665ef78dd8397b2de0b8e0028e80ce2 F src/test1.c 84c841e1088f743200b87581506e93f70344bd32 @@ -130,16 +130,16 @@ F src/tokenize.c 6cef9e6fc454d789a32c5b509ccb193a2b01977b F src/trigger.c 420192efe3e6f03addf7897c60c3c8bf913d3493 F src/update.c 3359041db390a8f856d67272f299600e2104f350 F src/utf.c b881fe54498f6a35de424a62f8e071b621111728 -F src/util.c a44710b94da6d0d606521a5e1fd40c8067282c74 +F src/util.c b99afc6940747ec504ac98ce551fc31181c3fcc0 F src/vacuum.c 8bd895d29e7074e78d4e80f948e35ddc9cf2beef -F src/vdbe.c d0f60420211ce8c298ea37d1832105741b27af0f +F src/vdbe.c 51baf9ba77e986db857c69d63a979bb5227317ae F src/vdbe.h 001c5b257567c1d3de7feb2203aac71d0d7b16a3 F src/vdbeInt.h 7d2bf163d6d4e815724a457f2216dd8e38c3955c F src/vdbeapi.c f89d6bc5264e66f44589e454fbeeee96854d0dd3 F src/vdbeaux.c 62011e2ccf5fa9b3dcc7fa6ff5f0e0638d324a70 F src/vdbeblob.c 96f3572fdc45eda5be06e6372b612bc30742d9f0 F src/vdbefifo.c 3ca8049c561d5d67cbcb94dc909ae9bb68c0bf8f -F src/vdbemem.c 596624a0b71aa2fb052cae640342dae9c734f8ad +F src/vdbemem.c 89ffe903b4de158b29fe8459f6f816d1f860d4ee F src/vtab.c c5ebebf615b2f29499fbe97a584c4bb342632aa0 F src/where.c f3920748cc650fc25ac916215500bdb90dee568e F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617 @@ -492,7 +492,7 @@ F www/tclsqlite.tcl bb0d1357328a42b1993d78573e587c6dcbc964b9 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5 -P 57e17c7cda23a3b3e1d0a691af07c35c1c644dcc -R ef969dbd235873a63df830f4d99dc586 +P 1d89be287d34423b1a405cde0490260e7c731f07 +R 0c3a8d9f8c5cece70d3226582e2755a8 U danielk1977 -Z e60d12dc0d97c78167f71ea169cd880a +Z 6ba55ff12f0d9efe11930a5738e558b9 diff --git a/manifest.uuid b/manifest.uuid index 25db4c0151..7e0e025067 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1d89be287d34423b1a405cde0490260e7c731f07 \ No newline at end of file +93f811ec747f6a42daf9ee27cd8b013f248552a1 \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 5efdcc1dac..b3fd1f8bdf 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btree.c,v 1.381 2007/05/12 10:41:48 danielk1977 Exp $ +** $Id: btree.c,v 1.382 2007/05/16 17:28:43 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** See the header comment on "btreeInt.h" for additional information. @@ -419,11 +419,13 @@ static int ptrmapGet(BtShared *pBt, Pgno key, u8 *pEType, Pgno *pPgno){ ** ** This routine works only for pages that do not contain overflow cells. */ +#define findCell(pPage, iCell) \ + ((pPage)->aData + get2byte(&(pPage)->aData[(pPage)->cellOffset+2*(iCell)])) u8 *sqlite3BtreeFindCell(MemPage *pPage, int iCell){ u8 *data = pPage->aData; assert( iCell>=0 ); assert( iCellhdrOffset+3]) ); - return data + get2byte(&data[pPage->cellOffset+2*iCell]); + return findCell(pPage, iCell); } /* @@ -444,7 +446,7 @@ static u8 *findOverflowCell(MemPage *pPage, int iCell){ iCell--; } } - return sqlite3BtreeFindCell(pPage, iCell); + return findCell(pPage, iCell); } /* @@ -452,6 +454,9 @@ static u8 *findOverflowCell(MemPage *pPage, int iCell){ ** are two versions of this function. sqlite3BtreeParseCell() takes a ** cell index as the second argument and sqlite3BtreeParseCellPtr() ** takes a pointer to the body of the cell as its second argument. +** +** Within this file, the parseCell() macro can be called instead of +** sqlite3BtreeParseCellPtr(). Using some compilers, this will be faster. */ void sqlite3BtreeParseCellPtr( MemPage *pPage, /* Page containing the cell */ @@ -519,12 +524,14 @@ void sqlite3BtreeParseCellPtr( pInfo->nSize = pInfo->iOverflow + 4; } } +#define parseCell(pPage, iCell, pInfo) \ + sqlite3BtreeParseCellPtr((pPage), findCell((pPage), (iCell)), (pInfo)) void sqlite3BtreeParseCell( MemPage *pPage, /* Page containing the cell */ int iCell, /* The cell index. First cell is 0 */ CellInfo *pInfo /* Fill in this structure */ ){ - sqlite3BtreeParseCellPtr(pPage, sqlite3BtreeFindCell(pPage, iCell), pInfo); + parseCell(pPage, iCell, pInfo); } /* @@ -1661,7 +1668,7 @@ static int setChildPtrmaps(MemPage *pPage){ nCell = pPage->nCell; for(i=0; inCell; for(i=0; iinfo.nSize==0 ){ - sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info); - }else{ #ifndef NDEBUG + static void assertCellInfo(BtCursor *pCur){ CellInfo info; memset(&info, 0, sizeof(info)); sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &info); assert( memcmp(&info, &pCur->info, sizeof(info))==0 ); -#endif } -} +#else + #define assertCellInfo(x) +#endif + +#define GET_CELL_INFO(pCur) \ + if( pCur->info.nSize==0 ) \ + sqlite3BtreeParseCell(pCur->pPage, pCur->idx, &pCur->info); \ + else \ + assertCellInfo(pCur); + /* ** Set *pSize to the size of the buffer needed to hold the value of @@ -2489,7 +2503,7 @@ int sqlite3BtreeKeySize(BtCursor *pCur, i64 *pSize){ if( pCur->eState==CURSOR_INVALID ){ *pSize = 0; }else{ - getCellInfo(pCur); + GET_CELL_INFO(pCur); *pSize = pCur->info.nKey; } } @@ -2511,7 +2525,7 @@ int sqlite3BtreeDataSize(BtCursor *pCur, u32 *pSize){ /* Not pointing at a valid entry - set *pSize to 0. */ *pSize = 0; }else{ - getCellInfo(pCur); + GET_CELL_INFO(pCur); *pSize = pCur->info.nData; } } @@ -2684,7 +2698,7 @@ static int accessPayload( assert( pCur->idx>=0 && pCur->idxnCell ); assert( offset>=0 ); - getCellInfo(pCur); + GET_CELL_INFO(pCur); aPayload = pCur->info.pCell + pCur->info.nHeader; nKey = (pPage->intKey ? 0 : pCur->info.nKey); @@ -2874,7 +2888,7 @@ static const unsigned char *fetchPayload( assert( pCur->eState==CURSOR_VALID ); pPage = pCur->pPage; assert( pCur->idx>=0 && pCur->idxnCell ); - getCellInfo(pCur); + GET_CELL_INFO(pCur); aPayload = pCur->info.pCell; aPayload += pCur->info.nHeader; if( pPage->intKey ){ @@ -3045,7 +3059,7 @@ static int moveToLeftmost(BtCursor *pCur){ assert( pCur->eState==CURSOR_VALID ); while( !(pPage = pCur->pPage)->leaf ){ assert( pCur->idx>=0 && pCur->idxnCell ); - pgno = get4byte(sqlite3BtreeFindCell(pPage, pCur->idx)); + pgno = get4byte(findCell(pPage, pCur->idx)); rc = moveToChild(pCur, pgno); if( rc ) return rc; } @@ -3182,7 +3196,7 @@ int sqlite3BtreeMoveto( pCur->info.nSize = 0; if( pPage->intKey ){ u8 *pCell; - pCell = sqlite3BtreeFindCell(pPage, pCur->idx) + pPage->childPtrSize; + pCell = findCell(pPage, pCur->idx) + pPage->childPtrSize; if( pPage->hasData ){ u32 dummy; pCell += getVarint32(pCell, &dummy); @@ -3237,7 +3251,7 @@ int sqlite3BtreeMoveto( }else if( lwr>=pPage->nCell ){ chldPg = get4byte(&pPage->aData[pPage->hdrOffset+8]); }else{ - chldPg = get4byte(sqlite3BtreeFindCell(pPage, lwr)); + chldPg = get4byte(findCell(pPage, lwr)); } if( chldPg==0 ){ assert( pCur->idx>=0 && pCur->idxpPage->nCell ); @@ -3364,7 +3378,7 @@ int sqlite3BtreePrevious(BtCursor *pCur, int *pRes){ assert( pPage->isInit ); assert( pCur->idx>=0 ); if( !pPage->leaf ){ - pgno = get4byte( sqlite3BtreeFindCell(pPage, pCur->idx) ); + pgno = get4byte( findCell(pPage, pCur->idx) ); rc = moveToChild(pCur, pgno); if( rc ) return rc; rc = moveToRightmost(pCur); @@ -3933,7 +3947,7 @@ static int reparentChildPages(MemPage *pPage){ if( pPage->leaf ) return SQLITE_OK; for(i=0; inCell; i++){ - u8 *pCell = sqlite3BtreeFindCell(pPage, i); + u8 *pCell = findCell(pPage, i); if( !pPage->leaf ){ rc = reparentPage(pBt, get4byte(pCell), pPage, i); if( rc!=SQLITE_OK ) return rc; @@ -4187,7 +4201,7 @@ static int balance_quick(MemPage *pPage, MemPage *pParent){ ** pPage is the next-to-right child. */ assert( pPage->nCell>0 ); - pCell = sqlite3BtreeFindCell(pPage, pPage->nCell-1); + pCell = findCell(pPage, pPage->nCell-1); sqlite3BtreeParseCellPtr(pPage, pCell, &info); rc = fillInCell(pParent, parentCell, 0, info.nKey, 0, 0, 0, &parentSize); if( rc!=SQLITE_OK ){ @@ -4337,7 +4351,7 @@ static int balance_nonroot(MemPage *pPage){ pgno = pPage->pgno; assert( pgno==sqlite3PagerPagenumber(pPage->pDbPage) ); for(idx=0; idxnCell; idx++){ - if( get4byte(sqlite3BtreeFindCell(pParent, idx))==pgno ){ + if( get4byte(findCell(pParent, idx))==pgno ){ break; } } @@ -4371,7 +4385,7 @@ static int balance_nonroot(MemPage *pPage){ nDiv = 0; for(i=0, k=nxDiv; inCell ){ - apDiv[i] = sqlite3BtreeFindCell(pParent, k); + apDiv[i] = findCell(pParent, k); nDiv++; assert( !pParent->leaf ); pgnoOld[i] = get4byte(apDiv[i]); @@ -4872,7 +4886,7 @@ static int balance_shallower(MemPage *pPage){ int i; zeroPage(pPage, pChild->aData[0]); for(i=0; inCell; i++){ - apCell[i] = sqlite3BtreeFindCell(pChild,i); + apCell[i] = findCell(pChild,i); szCell[i] = cellSizePtr(pChild, apCell[i]); } assemblePage(pPage, pChild->nCell, apCell, szCell); @@ -5105,7 +5119,7 @@ int sqlite3BtreeInsert( if( loc==0 && CURSOR_VALID==pCur->eState ){ int szOld; assert( pCur->idx>=0 && pCur->idxnCell ); - oldCell = sqlite3BtreeFindCell(pPage, pCur->idx); + oldCell = findCell(pPage, pCur->idx); if( !pPage->leaf ){ memcpy(newCell, oldCell, 4); } @@ -5177,7 +5191,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){ ** data. The clearCell() call frees any overflow pages associated with the ** cell. The cell itself is still intact. */ - pCell = sqlite3BtreeFindCell(pPage, pCur->idx); + pCell = findCell(pPage, pCur->idx); if( !pPage->leaf ){ pgnoChild = get4byte(pCell); } @@ -5209,7 +5223,7 @@ int sqlite3BtreeDelete(BtCursor *pCur){ TRACE(("DELETE: table=%d delete internal from %d replace from leaf %d\n", pCur->pgnoRoot, pPage->pgno, leafCur.pPage->pgno)); dropCell(pPage, pCur->idx, cellSizePtr(pPage, pCell)); - pNext = sqlite3BtreeFindCell(leafCur.pPage, leafCur.idx); + pNext = findCell(leafCur.pPage, leafCur.idx); szNext = cellSizePtr(leafCur.pPage, pNext); assert( MX_CELL_SIZE(pBt)>=szNext+4 ); tempCell = sqliteMallocRaw( MX_CELL_SIZE(pBt) ); @@ -5400,7 +5414,7 @@ static int clearDatabasePage( rc = getAndInitPage(pBt, pgno, &pPage, pParent); if( rc ) goto cleardatabasepage_out; for(i=0; inCell; i++){ - pCell = sqlite3BtreeFindCell(pPage, i); + pCell = findCell(pPage, i); if( !pPage->leaf ){ rc = clearDatabasePage(pBt, get4byte(pCell), pPage->pParent, 1); if( rc ) goto cleardatabasepage_out; @@ -5887,7 +5901,7 @@ static int checkTreePage( */ sqlite3_snprintf(sizeof(zContext), zContext, "On tree page %d cell %d: ", iPage, i); - pCell = sqlite3BtreeFindCell(pPage,i); + pCell = findCell(pPage,i); sqlite3BtreeParseCellPtr(pPage, pCell, &info); sz = info.nData; if( !pPage->intKey ) sz += info.nKey; diff --git a/src/btreeInt.h b/src/btreeInt.h index abd5ed7139..89af4e498c 100644 --- a/src/btreeInt.h +++ b/src/btreeInt.h @@ -9,7 +9,7 @@ ** May you share freely, never taking more than you give. ** ************************************************************************* -** $Id: btreeInt.h,v 1.3 2007/05/16 14:23:00 danielk1977 Exp $ +** $Id: btreeInt.h,v 1.4 2007/05/16 17:28:43 danielk1977 Exp $ ** ** This file implements a external (disk-based) database using BTrees. ** For a detailed discussion of BTrees, refer to @@ -570,9 +570,9 @@ struct IntegrityCk { /* ** Read or write a two- and four-byte big-endian integer values. */ -#define get2byte(x) ((x)[0]<<8 | (x)[1]) +#define get2byte(x) ((x)[0]<<8 | (x)[1]) +#define put2byte(p,v) ((p)[0] = (v)>>8, (p)[1] = (v)) #define get4byte sqlite3Get4byte -#define put2byte sqlite3Put2byte #define put4byte sqlite3Put4byte /* diff --git a/src/malloc.c b/src/malloc.c index 524f5ea605..e8124a34df 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -12,7 +12,7 @@ ** Memory allocation functions used throughout sqlite. ** ** -** $Id: malloc.c,v 1.1 2007/05/05 11:48:54 drh Exp $ +** $Id: malloc.c,v 1.2 2007/05/16 17:28:43 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -788,10 +788,10 @@ void sqlite3SetString(char **pz, ...){ ** then the connection error-code (the value returned by sqlite3_errcode()) ** is set to SQLITE_NOMEM. */ -static int mallocHasFailed = 0; +int sqlite3_mallocHasFailed = 0; int sqlite3ApiExit(sqlite3* db, int rc){ if( sqlite3MallocFailed() ){ - mallocHasFailed = 0; + sqlite3_mallocHasFailed = 0; sqlite3OsLeaveMutex(); sqlite3Error(db, SQLITE_NOMEM, 0); rc = SQLITE_NOMEM; @@ -799,22 +799,14 @@ int sqlite3ApiExit(sqlite3* db, int rc){ return rc & (db ? db->errMask : 0xff); } -/* -** Return true is a malloc has failed in this thread since the last call -** to sqlite3ApiExit(), or false otherwise. -*/ -int sqlite3MallocFailed(){ - return (mallocHasFailed && sqlite3OsInMutex(1)); -} - /* ** Set the "malloc has failed" condition to true for this thread. */ void sqlite3FailedMalloc(){ if( !sqlite3MallocFailed() ){ sqlite3OsEnterMutex(); - assert( mallocHasFailed==0 ); - mallocHasFailed = 1; + assert( sqlite3_mallocHasFailed==0 ); + sqlite3_mallocHasFailed = 1; } } diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 1b831f20f6..3f28e145c6 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -11,7 +11,7 @@ ************************************************************************* ** Internal interface definitions for SQLite. ** -** @(#) $Id: sqliteInt.h,v 1.568 2007/05/15 16:51:37 drh Exp $ +** @(#) $Id: sqliteInt.h,v 1.569 2007/05/16 17:28:43 danielk1977 Exp $ */ #ifndef _SQLITEINT_H_ #define _SQLITEINT_H_ @@ -254,10 +254,19 @@ extern int sqlite3_iLine; /* Line number for debug info */ #endif +/* Variable sqlite3_mallocHasFailed is set to true after a malloc() +** failure occurs. +** +** The sqlite3MallocFailed() macro returns true if a malloc has failed +** in this thread since the last call to sqlite3ApiExit(), or false +** otherwise. +*/ +extern int sqlite3_mallocHasFailed; +#define sqlite3MallocFailed() (sqlite3_mallocHasFailed && sqlite3OsInMutex(1)) + #define sqliteFree(x) sqlite3FreeX(x) #define sqliteAllocSize(x) sqlite3AllocSize(x) - /* ** An instance of this structure might be allocated to store information ** specific to a single thread. @@ -333,6 +342,8 @@ typedef struct Trigger Trigger; typedef struct WhereInfo WhereInfo; typedef struct WhereLevel WhereLevel; +#include "os.h" + /* ** Each database file to be accessed by the system is an instance ** of the following structure. There are normally two of these structures @@ -1878,7 +1889,6 @@ int sqlite3CreateFunc(sqlite3 *, const char *, int, int, void *, void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*,int,sqlite3_value **), void (*)(sqlite3_context*)); int sqlite3ApiExit(sqlite3 *db, int); -int sqlite3MallocFailed(void); void sqlite3FailedMalloc(void); void sqlite3AbortOtherActiveVdbes(sqlite3 *, Vdbe *); int sqlite3OpenTempDatabase(Parse *); diff --git a/src/util.c b/src/util.c index 8d942b0680..031c07b68e 100644 --- a/src/util.c +++ b/src/util.c @@ -14,7 +14,7 @@ ** This file contains functions for allocating memory, comparing ** strings, and stuff like that. ** -** $Id: util.c,v 1.203 2007/05/15 16:51:37 drh Exp $ +** $Id: util.c,v 1.204 2007/05/16 17:28:43 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -537,18 +537,11 @@ int sqlite3VarintLen(u64 v){ /* -** Read or write a two- and four-byte big-endian integer values. +** Read or write a four-byte big-endian integer value. */ -u32 sqlite3Get2byte(const u8 *p){ - return (p[0]<<8) | p[1]; -} u32 sqlite3Get4byte(const u8 *p){ return (p[0]<<24) | (p[1]<<16) | (p[2]<<8) | p[3]; } -void sqlite3Put2byte(unsigned char *p, u32 v){ - p[0] = v>>8; - p[1] = v; -} void sqlite3Put4byte(unsigned char *p, u32 v){ p[0] = v>>24; p[1] = v>>16; diff --git a/src/vdbe.c b/src/vdbe.c index a8aad0c871..a9f19ad36d 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.620 2007/05/16 14:23:00 danielk1977 Exp $ +** $Id: vdbe.c,v 1.621 2007/05/16 17:28:43 danielk1977 Exp $ */ #include "sqliteInt.h" #include "os.h" @@ -151,6 +151,12 @@ int sqlite3_max_blobsize = 0; if( ((P)->flags&MEM_Ephem)!=0 \ && sqlite3VdbeMemMakeWriteable(P) ){ goto no_mem;} +/* +** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) +** P if required. +*/ +#define ExpandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) + /* ** Argument pMem points at a memory cell that will be passed to a ** user-defined function or returned to the user as the result of a query. @@ -1470,7 +1476,7 @@ case OP_ToText: { /* same as TK_TO_TEXT, no-push */ assert( MEM_Str==(MEM_Blob>>3) ); pTos->flags |= (pTos->flags&MEM_Blob)>>3; applyAffinity(pTos, SQLITE_AFF_TEXT, encoding); - rc = sqlite3VdbeMemExpandBlob(pTos); + rc = ExpandBlob(pTos); assert( pTos->flags & MEM_Str ); pTos->flags &= ~(MEM_Int|MEM_Real|MEM_Blob); break; @@ -1675,8 +1681,8 @@ case OP_Ge: { /* same as TK_GE, no-push */ } assert( pOp->p3type==P3_COLLSEQ || pOp->p3==0 ); - sqlite3VdbeMemExpandBlob(pNos); - sqlite3VdbeMemExpandBlob(pTos); + ExpandBlob(pNos); + ExpandBlob(pTos); res = sqlite3MemCompare(pNos, pTos, (CollSeq*)pOp->p3); switch( pOp->opcode ){ case OP_Eq: res = res==0; break; @@ -2275,7 +2281,7 @@ case OP_MakeRecord: { containsNull = 1; } if( pRec->flags&MEM_Zero && pRec->n>0 ){ - sqlite3VdbeMemExpandBlob(pRec); + ExpandBlob(pRec); } serial_type = sqlite3VdbeSerialType(pRec, file_format); len = sqlite3VdbeSerialTypeLen(serial_type); @@ -2928,7 +2934,7 @@ case OP_MoveGt: { /* no-push */ pC->rowidIsValid = res==0; }else{ assert( pTos->flags & MEM_Blob ); - sqlite3VdbeMemExpandBlob(pTos); + ExpandBlob(pTos); rc = sqlite3BtreeMoveto(pC->pCursor, pTos->z, pTos->n, 0, &res); if( rc!=SQLITE_OK ){ goto abort_due_to_error; @@ -3831,7 +3837,7 @@ case OP_IdxInsert: { /* no-push */ assert( pTos->flags & MEM_Blob ); if( (pCrsr = (pC = p->apCsr[i])->pCursor)!=0 ){ assert( pC->isTable==0 ); - rc = sqlite3VdbeMemExpandBlob(pTos); + rc = ExpandBlob(pTos); if( rc==SQLITE_OK ){ int nKey = pTos->n; const char *zKey = pTos->z; @@ -3967,7 +3973,7 @@ case OP_IdxGE: { /* no-push */ assert( pTos->flags & MEM_Blob ); /* Created using OP_MakeRecord */ assert( pC->deferredMoveto==0 ); - sqlite3VdbeMemExpandBlob(pTos); + ExpandBlob(pTos); *pC->pIncrKey = pOp->p3!=0; assert( pOp->p3==0 || pOp->opcode!=OP_IdxGT ); rc = sqlite3VdbeIdxKeyCompare(pC, pTos->n, (u8*)pTos->z, &res); diff --git a/src/vdbemem.c b/src/vdbemem.c index 5d8d2b8fa6..f65ac6aaff 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -21,6 +21,12 @@ #include #include "vdbeInt.h" +/* +** Call sqlite3VdbeMemExpandBlob() on the supplied value (type Mem*) +** P if required. +*/ +#define expandBlob(P) (((P)->flags&MEM_Zero)?sqlite3VdbeMemExpandBlob(P):0) + /* ** If pMem is an object with a valid string representation, this routine ** ensures the internal encoding for the string representation is @@ -63,7 +69,7 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ int sqlite3VdbeMemDynamicify(Mem *pMem){ int n; u8 *z; - sqlite3VdbeMemExpandBlob(pMem); + expandBlob(pMem); if( (pMem->flags & (MEM_Ephem|MEM_Static|MEM_Short))==0 ){ return SQLITE_OK; } @@ -120,7 +126,7 @@ int sqlite3VdbeMemExpandBlob(Mem *pMem){ int sqlite3VdbeMemMakeWriteable(Mem *pMem){ int n; u8 *z; - sqlite3VdbeMemExpandBlob(pMem); + expandBlob(pMem); if( (pMem->flags & (MEM_Ephem|MEM_Static))==0 ){ return SQLITE_OK; } @@ -836,7 +842,7 @@ const void *sqlite3ValueText(sqlite3_value* pVal, u8 enc){ } assert( (MEM_Blob>>3) == MEM_Str ); pVal->flags |= (pVal->flags & MEM_Blob)>>3; - sqlite3VdbeMemExpandBlob(pVal); + expandBlob(pVal); if( pVal->flags&MEM_Str ){ sqlite3VdbeChangeEncoding(pVal, enc & ~SQLITE_UTF16_ALIGNED); if( (enc & SQLITE_UTF16_ALIGNED)!=0 && 1==(1&(int)pVal->z) ){