From: drh Date: Thu, 2 Feb 2012 03:38:30 +0000 (+0000) Subject: Simplified array allocation in the IdList and AggInfo objects. X-Git-Tag: version-3.7.11~66 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6c5351589c94536a16f4798afb5beaf415cabb9f;p=thirdparty%2Fsqlite.git Simplified array allocation in the IdList and AggInfo objects. FossilOrigin-Name: 25df2a7458d025bc00380b4a0893637639f9f0d4 --- diff --git a/manifest b/manifest index e1bfc75fb2..5ff10338c5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spossible\ssegfault\safter\san\sOOM\sfault.\s\sThis\shas\sbeen\sin\sthe\scode\sfor\sages\nbut\sonly\sexpressed\sitself\sfollowing\sthe\sprevious\scheck-in. -D 2012-02-02T03:11:40.324 +C Simplified\sarray\sallocation\sin\sthe\sIdList\sand\sAggInfo\sobjects. +D 2012-02-02T03:38:30.479 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 3f79a373e57c3b92dabf76f40b065e719d31ac34 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -128,13 +128,13 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7 F src/btree.c 24bde768288b3365bc6acfbb24030f76fefe7e1f F src/btree.h 46e9f04672f1390255bc56865a3238b384d0f2d5 F src/btreeInt.h 6c9960645c431c9456ca56498f43a2b3bf1fa8c2 -F src/build.c 8e2a4dedad860fed982270ef43968505f35ec57f +F src/build.c 7a03d1772f906ca1ba905858b4f19d4d8b34e59d F src/callback.c 0425c6320730e6d3981acfb9202c1bed9016ad1a F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac F src/ctime.c a9c26822515f81ec21588cbb482ca6724be02e33 F src/date.c 067a81c9942c497aafd2c260e13add8a7d0c7dd4 F src/delete.c 51d32f0a9c880663e54ce309f52e40c325d5e112 -F src/expr.c d644aac3409c67c9a9bcf9d5098641b18b47d925 +F src/expr.c 00675123e0beec98f999aa4594d2cbe1fec33c1b F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c 657212460bf5cfd3ae607d12ea62092844c227b5 F src/func.c 6261ce00aad9c63cd5b4219249b05683979060e9 @@ -184,7 +184,7 @@ F src/select.c b6eec9d11ec5df0d1fd11e8a0eed0fc2d2d96b25 F src/shell.c 60d147c2411dd2d79a5151cfb9a068de87c7babe F src/sqlite.h.in 371c30e4be94b9b0ea6400ed66663fcf8e891eb4 F src/sqlite3ext.h 6904f4aadf976f95241311fbffb00823075d9477 -F src/sqliteInt.h f6b1d14dbabf8bc86f7d48da64c1ed881c747eb8 +F src/sqliteInt.h e4275be35f82b3da4734d0d8eb97c618a91bb1a1 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c 4568e72dfd36b6a5911f93457364deb072e0b03a F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -988,7 +988,7 @@ F tool/tostr.awk e75472c2f98dd76e06b8c9c1367f4ab07e122d06 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f F tool/warnings-clang.sh 9f406d66e750e8ac031c63a9ef3248aaa347ef2a F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 -P 5963de303a9106b446a9423aa838bfdf6bc1e7f3 -R 850cb01b34139b6ff5ae22e6f4202f6f +P a3553b8a035b70e76a5a325b9e9f379f84de3955 +R 0dee572dcbe8f4a7b8dff88e26875d80 U drh -Z ef5893d9871699934600cb710a85a051 +Z 566ebf07e0f933f12b6e71767840fbdb diff --git a/manifest.uuid b/manifest.uuid index 56ca8ab76d..fa04a3cae9 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a3553b8a035b70e76a5a325b9e9f379f84de3955 \ No newline at end of file +25df2a7458d025bc00380b4a0893637639f9f0d4 \ No newline at end of file diff --git a/src/build.c b/src/build.c index 5798e7322e..ac5bfadaa8 100644 --- a/src/build.c +++ b/src/build.c @@ -3059,27 +3059,23 @@ void *sqlite3ArrayAllocate( sqlite3 *db, /* Connection to notify of malloc failures */ void *pArray, /* Array of objects. Might be reallocated */ int szEntry, /* Size of each object in the array */ - int initSize, /* Suggested initial allocation, in elements */ int *pnEntry, /* Number of objects currently in use */ - int *pnAlloc, /* Current size of the allocation, in elements */ int *pIdx /* Write the index of a new slot here */ ){ char *z; - if( *pnEntry >= *pnAlloc ){ - void *pNew; - int newSize; - newSize = (*pnAlloc)*2 + initSize; - pNew = sqlite3DbRealloc(db, pArray, newSize*szEntry); + int n = *pnEntry; + if( (n & (n-1))==0 ){ + int sz = (n==0) ? 1 : 2*n; + void *pNew = sqlite3DbRealloc(db, pArray, sz*szEntry); if( pNew==0 ){ *pIdx = -1; return pArray; } - *pnAlloc = sqlite3DbMallocSize(db, pNew)/szEntry; pArray = pNew; } z = (char*)pArray; - memset(&z[*pnEntry * szEntry], 0, szEntry); - *pIdx = *pnEntry; + memset(&z[n * szEntry], 0, szEntry); + *pIdx = n; ++*pnEntry; return pArray; } @@ -3095,15 +3091,12 @@ IdList *sqlite3IdListAppend(sqlite3 *db, IdList *pList, Token *pToken){ if( pList==0 ){ pList = sqlite3DbMallocZero(db, sizeof(IdList) ); if( pList==0 ) return 0; - pList->nAlloc = 0; } pList->a = sqlite3ArrayAllocate( db, pList->a, sizeof(pList->a[0]), - 5, &pList->nId, - &pList->nAlloc, &i ); if( i<0 ){ diff --git a/src/expr.c b/src/expr.c index 5034d40aeb..79dd8f4961 100644 --- a/src/expr.c +++ b/src/expr.c @@ -926,12 +926,15 @@ IdList *sqlite3IdListDup(sqlite3 *db, IdList *p){ if( p==0 ) return 0; pNew = sqlite3DbMallocRaw(db, sizeof(*pNew) ); if( pNew==0 ) return 0; - pNew->nId = pNew->nAlloc = p->nId; + pNew->nId = p->nId; pNew->a = sqlite3DbMallocRaw(db, p->nId*sizeof(p->a[0]) ); if( pNew->a==0 ){ sqlite3DbFree(db, pNew); return 0; } + /* Note that because the size of the allocation for p->a[] is not + ** necessarily a power of two, sqlite3IdListAppend() may not be called + ** on the duplicate created by this function. */ for(i=0; inId; i++){ struct IdList_item *pNewItem = &pNew->a[i]; struct IdList_item *pOldItem = &p->a[i]; @@ -3774,9 +3777,7 @@ static int addAggInfoColumn(sqlite3 *db, AggInfo *pInfo){ db, pInfo->aCol, sizeof(pInfo->aCol[0]), - 3, &pInfo->nColumn, - &pInfo->nColumnAlloc, &i ); return i; @@ -3792,9 +3793,7 @@ static int addAggInfoFunc(sqlite3 *db, AggInfo *pInfo){ db, pInfo->aFunc, sizeof(pInfo->aFunc[0]), - 3, &pInfo->nFunc, - &pInfo->nFuncAlloc, &i ); return i; diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 2d95feff20..0ce3d7b226 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1567,7 +1567,6 @@ struct AggInfo { Expr *pExpr; /* The original expression */ } *aCol; int nColumn; /* Number of used entries in aCol[] */ - int nColumnAlloc; /* Number of slots allocated for aCol[] */ int nAccumulator; /* Number of columns that show through to the output. ** Additional columns are used only as parameters to ** aggregate functions */ @@ -1578,7 +1577,6 @@ struct AggInfo { int iDistinct; /* Ephemeral table used to enforce DISTINCT */ } *aFunc; int nFunc; /* Number of entries in aFunc[] */ - int nFuncAlloc; /* Number of slots allocated for aFunc[] */ }; /* @@ -1819,7 +1817,6 @@ struct IdList { int idx; /* Index in some Table.aCol[] of a column named zName */ } *a; int nId; /* Number of identifiers on the list */ - int nAlloc; /* Number of entries allocated for a[] below */ }; /* @@ -2762,7 +2759,7 @@ void sqlite3DeleteTable(sqlite3*, Table*); # define sqlite3AutoincrementEnd(X) #endif void sqlite3Insert(Parse*, SrcList*, ExprList*, Select*, IdList*, int); -void *sqlite3ArrayAllocate(sqlite3*,void*,int,int,int*,int*,int*); +void *sqlite3ArrayAllocate(sqlite3*,void*,int,int*,int*); IdList *sqlite3IdListAppend(sqlite3*, IdList*, Token*); int sqlite3IdListIndex(IdList*,const char*); SrcList *sqlite3SrcListEnlarge(sqlite3*, SrcList*, int, int);