From: drh Date: Tue, 10 Dec 2013 19:49:00 +0000 (+0000) Subject: Simplify and improve the performance of the sqlite3VdbeMemGrow() routine. X-Git-Tag: version-3.8.3~109 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b0e7704e9f4bff5ad5213921b9e8c5a5d77698af;p=thirdparty%2Fsqlite.git Simplify and improve the performance of the sqlite3VdbeMemGrow() routine. FossilOrigin-Name: 48ecf18774ba9572d86696c60d87007a619d9f53 --- diff --git a/manifest b/manifest index 6901566020..1bdefb7a11 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Simplifications\sto\sthe\sOP_MakeRecord\sopcode\sand\sthe\ssqlite3VdbeSerialPut()\nhelper\sfunction. -D 2013-12-09T23:17:22.886 +C Simplify\sand\simprove\sthe\sperformance\sof\sthe\ssqlite3VdbeMemGrow()\sroutine. +D 2013-12-10T19:49:00.802 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -188,8 +188,8 @@ F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d F src/legacy.c 0df0b1550b9cc1f58229644735e317ac89131f12 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303 -F src/main.c 355fc9ab213b43a4d8a96aadf2a84622e6668f0a -F src/malloc.c 543a8eb5508eaf4cadf55a9b503379eba2088128 +F src/main.c a79c8ca051a914e50d6b221d56801d47835714d8 +F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645 F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b F src/mem2.c dce31758da87ec2cfa52ba4c5df1aed6e07d8e8f @@ -286,7 +286,7 @@ F src/vdbeInt.h 7e38eef8f4bd7141e1638b0eacaebf9bc41b26bc F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed F src/vdbeaux.c d64bc2a057e77aef3e2a4bc6670b80f516a36d55 F src/vdbeblob.c 8cd05a5630e6d5563ad017bf82edaf812b28acde -F src/vdbemem.c 2293b66374f4adf54bbdcd662c05a003318600e1 +F src/vdbemem.c a381254caef0d102b091923a309c4c3a06a65393 F src/vdbesort.c 9d83601f9d6243fe70dd0169a2820c5ddfd48147 F src/vdbetrace.c e7ec40e1999ff3c6414424365d5941178966dcbc F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd @@ -1146,7 +1146,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P c43b59dac1fbb67ec3a9d921005543046ad416ce -R c11616a6774c1e84bdec6602d7be1c45 +P 7277a769694787e0332d1a4efc02041834661e2a +R 3ef0e61f6611b17b108322b8d504b195 U drh -Z 4d30567758bc854237be3d93d5ebeaed +Z 641e108686357e5c2dc6bc5a433b2dd9 diff --git a/manifest.uuid b/manifest.uuid index fae0da29de..fd40777301 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -7277a769694787e0332d1a4efc02041834661e2a \ No newline at end of file +48ecf18774ba9572d86696c60d87007a619d9f53 \ No newline at end of file diff --git a/src/main.c b/src/main.c index 1ba555fde8..3e9f4e0171 100644 --- a/src/main.c +++ b/src/main.c @@ -588,7 +588,8 @@ static int setupLookaside(sqlite3 *db, void *pBuf, int sz, int cnt){ db->lookaside.bEnabled = 1; db->lookaside.bMalloced = pBuf==0 ?1:0; }else{ - db->lookaside.pEnd = 0; + db->lookaside.pStart = db; + db->lookaside.pEnd = db; db->lookaside.bEnabled = 0; db->lookaside.bMalloced = 0; } diff --git a/src/malloc.c b/src/malloc.c index 799f0485d4..9c11d07767 100644 --- a/src/malloc.c +++ b/src/malloc.c @@ -433,7 +433,7 @@ void sqlite3ScratchFree(void *p){ */ #ifndef SQLITE_OMIT_LOOKASIDE static int isLookaside(sqlite3 *db, void *p){ - return p && p>=db->lookaside.pStart && plookaside.pEnd; + return p>=db->lookaside.pStart && plookaside.pEnd; } #else #define isLookaside(A,B) 0 @@ -449,8 +449,9 @@ int sqlite3MallocSize(void *p){ return sqlite3GlobalConfig.m.xSize(p); } int sqlite3DbMallocSize(sqlite3 *db, void *p){ - assert( db==0 || sqlite3_mutex_held(db->mutex) ); - if( db && isLookaside(db, p) ){ + assert( db!=0 ); + assert( sqlite3_mutex_held(db->mutex) ); + if( isLookaside(db, p) ){ return db->lookaside.sz; }else{ assert( sqlite3MemdebugHasType(p, MEMTYPE_DB) ); diff --git a/src/vdbemem.c b/src/vdbemem.c index 451744291f..6a0a66ead2 100644 --- a/src/vdbemem.c +++ b/src/vdbemem.c @@ -59,18 +59,14 @@ int sqlite3VdbeChangeEncoding(Mem *pMem, int desiredEnc){ /* ** Make sure pMem->z points to a writable allocation of at least -** n bytes. +** min(n,32) bytes. ** -** If the third argument passed to this function is true, then memory -** cell pMem must contain a string or blob. In this case the content is -** preserved. Otherwise, if the third parameter to this function is false, -** any current string or blob value may be discarded. -** -** This function sets the MEM_Dyn flag and clears any xDel callback. -** It also clears MEM_Ephem and MEM_Static. If the preserve flag is -** not set, Mem.n is zeroed. +** If the bPreserve argument is true, then copy of the content of +** pMem->z into the new allocation. pMem must be either a string or +** blob if bPreserve is true. If bPreserve is false, any prior content +** in pMem->z is discarded. */ -int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ +int sqlite3VdbeMemGrow(Mem *pMem, int n, int bPreserve){ assert( 1 >= ((pMem->zMalloc && pMem->zMalloc==pMem->z) ? 1 : 0) + (((pMem->flags&MEM_Dyn)&&pMem->xDel) ? 1 : 0) + @@ -79,37 +75,39 @@ int sqlite3VdbeMemGrow(Mem *pMem, int n, int preserve){ ); assert( (pMem->flags&MEM_RowSet)==0 ); - /* If the preserve flag is set to true, then the memory cell must already + /* If the bPreserve flag is set to true, then the memory cell must already ** contain a valid string or blob value. */ - assert( preserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); + assert( bPreserve==0 || pMem->flags&(MEM_Blob|MEM_Str) ); + testcase( bPreserve && pMem->z==0 ); - if( n<32 ) n = 32; - if( sqlite3DbMallocSize(pMem->db, pMem->zMalloc)z==pMem->zMalloc ){ + if( pMem->zMalloc==0 || sqlite3DbMallocSize(pMem->db, pMem->zMalloc)z==pMem->zMalloc ){ pMem->z = pMem->zMalloc = sqlite3DbReallocOrFree(pMem->db, pMem->z, n); - preserve = 0; + bPreserve = 0; }else{ sqlite3DbFree(pMem->db, pMem->zMalloc); pMem->zMalloc = sqlite3DbMallocRaw(pMem->db, n); } + if( pMem->zMalloc==0 ){ + sqlite3VdbeMemRelease(pMem); + pMem->flags = MEM_Null; + return SQLITE_NOMEM; + } } - if( pMem->z && preserve && pMem->zMalloc && pMem->z!=pMem->zMalloc ){ + if( pMem->z && bPreserve && pMem->z!=pMem->zMalloc ){ memcpy(pMem->zMalloc, pMem->z, pMem->n); } - if( pMem->flags&MEM_Dyn && pMem->xDel ){ + if( (pMem->flags&MEM_Dyn)!=0 && pMem->xDel ){ assert( pMem->xDel!=SQLITE_DYNAMIC ); pMem->xDel((void *)(pMem->z)); } pMem->z = pMem->zMalloc; - if( pMem->z==0 ){ - pMem->flags = MEM_Null; - }else{ - pMem->flags &= ~(MEM_Ephem|MEM_Static); - } + pMem->flags &= ~(MEM_Ephem|MEM_Static); pMem->xDel = 0; - return (pMem->z ? SQLITE_OK : SQLITE_NOMEM); + return SQLITE_OK; } /*