Simplify the interface to the symbol table, saving 600 bytes of code space.
FossilOrigin-Name: 14b0f561fe15622b61c6676c9c455dca6b9ba5f0
This commit is contained in:
parent
b6b4b79f34
commit
acbcb7e013
26
manifest
26
manifest
@ -1,5 +1,5 @@
|
|||||||
C Fix\sa\sfaulty\sassert()\sstatement.\s\sAdd\scomments\sto\sclarify\sthe\sbehavior\sof\nthe\ssqlite3OpenTableAndIndices()\sroutine\sin\sinsert.c.\s\sAdd\stest\scases\sto\nverify\sthat\sthe\sassert()\sstatement\sis\snot\sfiring\sinappropriately.\nTicket\s[369d57fb8e5ccdff06f1].
|
C Simplify\sthe\sinterface\sto\sthe\ssymbol\stable,\ssaving\s600\sbytes\sof\scode\sspace.
|
||||||
D 2014-08-21T14:10:23.770
|
D 2014-08-21T20:26:37.728
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
|
F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@ -171,26 +171,26 @@ F src/btmutex.c 976f45a12e37293e32cae0281b15a21d48a8aaa7
|
|||||||
F src/btree.c 4195fed5741b4dbcc9831b623aec487258f3e62d
|
F src/btree.c 4195fed5741b4dbcc9831b623aec487258f3e62d
|
||||||
F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a
|
F src/btree.h 4245a349bfe09611d7ff887dbc3a80cee8b7955a
|
||||||
F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3
|
F src/btreeInt.h cf180d86b2e9e418f638d65baa425c4c69c0e0e3
|
||||||
F src/build.c 5abf794fe8a605f2005b422e98a3cedad9b9ef5b
|
F src/build.c 058e3aadb1376521ff291735237edf4c10f438fb
|
||||||
F src/callback.c fcff28cf0df2403dd2f313bb8d1b8f31f6f3cd64
|
F src/callback.c b97d0695ffcf6a8710ee445ffe56ee387d4d8a6f
|
||||||
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
|
||||||
F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a
|
F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a
|
||||||
F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
|
F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
|
||||||
F src/delete.c 5adcd322c6b08fc25d215d780ca62cebce66304d
|
F src/delete.c 5adcd322c6b08fc25d215d780ca62cebce66304d
|
||||||
F src/expr.c f749009cf4a8534efb5e0d5cd7c9fb1fb0f2836c
|
F src/expr.c f749009cf4a8534efb5e0d5cd7c9fb1fb0f2836c
|
||||||
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
|
||||||
F src/fkey.c 8545f3b36da47473e10800ea4fb0810fd4062514
|
F src/fkey.c 8d81a780ad78d16ec9082585758a8f1d6bf02ca3
|
||||||
F src/func.c bbb724b74ed96ca42675a7274646a71dd52bcda7
|
F src/func.c bbb724b74ed96ca42675a7274646a71dd52bcda7
|
||||||
F src/global.c 1e4bd956dc2f608f87d2a929abc4a20db65f30e4
|
F src/global.c 1e4bd956dc2f608f87d2a929abc4a20db65f30e4
|
||||||
F src/hash.c d139319967164f139c8d1bb8a11b14db9c4ba3cd
|
F src/hash.c 4263fbc955f26c2e8cdc0cf214bc42435aa4e4f5
|
||||||
F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
|
F src/hash.h c8f3c31722cf3277d03713909761e152a5b81094
|
||||||
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
|
||||||
F src/insert.c d1a104e67b33314d4cc5c1356147446086ab9fc8
|
F src/insert.c d1a104e67b33314d4cc5c1356147446086ab9fc8
|
||||||
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
|
||||||
F src/legacy.c febc2a9e7ad6c1a6191c7b5b9170b325d263f343
|
F src/legacy.c febc2a9e7ad6c1a6191c7b5b9170b325d263f343
|
||||||
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
|
F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
|
||||||
F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303
|
F src/loadext.c 867c7b330b740c6c917af9956b13b81d0a048303
|
||||||
F src/main.c 1cf92c5c6468f2b6ed99b638706781ccc9c60b42
|
F src/main.c 1e5d34fb6dee85019b4bcc44e8576457b5075174
|
||||||
F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be
|
F src/malloc.c 0203ebce9152c6a0e5de520140b8ba65187350be
|
||||||
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
F src/mem0.c 6a55ebe57c46ca1a7d98da93aaa07f99f1059645
|
||||||
F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b
|
F src/mem1.c c0c990fcaddff810ea277b4fb5d9138603dd5d4b
|
||||||
@ -279,7 +279,7 @@ F src/test_vfs.c f84075a388527892ff184988f43b69ce69b8083c
|
|||||||
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
|
F src/test_vfstrace.c bab9594adc976cbe696ff3970728830b4c5ed698
|
||||||
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
|
F src/test_wsd.c 41cadfd9d97fe8e3e4e44f61a4a8ccd6f7ca8fe9
|
||||||
F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec
|
F src/tokenize.c ae45399d6252b4d736af43bee1576ce7bff86aec
|
||||||
F src/trigger.c 66f3470b03b52b395e839155786966e3e037fddb
|
F src/trigger.c 4bddd12803275aa98f1c7ce0118fceb02b2167f6
|
||||||
F src/update.c ea336ce7b8b3fc5e316ba8f082e6445babf81059
|
F src/update.c ea336ce7b8b3fc5e316ba8f082e6445babf81059
|
||||||
F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05
|
F src/utf.c a0314e637768a030e6e84a957d0c4f6ba910cc05
|
||||||
F src/util.c 3076bdd51cdbf60a6e2e57fada745be37133c73e
|
F src/util.c 3076bdd51cdbf60a6e2e57fada745be37133c73e
|
||||||
@ -293,7 +293,7 @@ F src/vdbeblob.c 9205ce9d3b064d9600f8418a897fc88b5687d9ac
|
|||||||
F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394
|
F src/vdbemem.c d90a1e8acf8b63dc9d14cbbea12bfec6cec31394
|
||||||
F src/vdbesort.c f7f5563bf7d4695ca8f3203f3bf9de96d04ed0b3
|
F src/vdbesort.c f7f5563bf7d4695ca8f3203f3bf9de96d04ed0b3
|
||||||
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
|
F src/vdbetrace.c 6f52bc0c51e144b7efdcfb2a8f771167a8816767
|
||||||
F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd
|
F src/vtab.c 180bfc5e69c92f2014c094bc49a66e8c37c188ac
|
||||||
F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a
|
F src/wal.c 264df50a1b33124130b23180ded2e2c5663c652a
|
||||||
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
|
||||||
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
|
F src/walker.c 11edb74d587bc87b33ca96a5173e3ec1b8389e45
|
||||||
@ -1188,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
|
|||||||
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
|
||||||
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
|
||||||
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
|
||||||
P 91594aae0725388765070c80039dfe1bf126392d
|
P 7029b3404d3f5f698a496934f3a3f2972051b257
|
||||||
R 25e887863ed8cfd2c8a241fac46385f1
|
R 818f77c3be876451b2dad41de8a59565
|
||||||
U drh
|
U drh
|
||||||
Z ed55b6e966354470a11e6c95fe10b90c
|
Z cb34ea9e2178e12926edef43b644d982
|
||||||
|
@ -1 +1 @@
|
|||||||
7029b3404d3f5f698a496934f3a3f2972051b257
|
14b0f561fe15622b61c6676c9c455dca6b9ba5f0
|
24
src/build.c
24
src/build.c
@ -286,16 +286,14 @@ void sqlite3NestedParse(Parse *pParse, const char *zFormat, ...){
|
|||||||
Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
|
Table *sqlite3FindTable(sqlite3 *db, const char *zName, const char *zDatabase){
|
||||||
Table *p = 0;
|
Table *p = 0;
|
||||||
int i;
|
int i;
|
||||||
int nName;
|
|
||||||
assert( zName!=0 );
|
assert( zName!=0 );
|
||||||
nName = sqlite3Strlen30(zName);
|
|
||||||
/* All mutexes are required for schema access. Make sure we hold them. */
|
/* All mutexes are required for schema access. Make sure we hold them. */
|
||||||
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
assert( zDatabase!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
||||||
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
||||||
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
||||||
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
|
if( zDatabase!=0 && sqlite3StrICmp(zDatabase, db->aDb[j].zName) ) continue;
|
||||||
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
||||||
p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName, nName);
|
p = sqlite3HashFind(&db->aDb[j].pSchema->tblHash, zName);
|
||||||
if( p ) break;
|
if( p ) break;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
@ -378,7 +376,6 @@ Table *sqlite3LocateTableItem(
|
|||||||
Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
|
Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
|
||||||
Index *p = 0;
|
Index *p = 0;
|
||||||
int i;
|
int i;
|
||||||
int nName = sqlite3Strlen30(zName);
|
|
||||||
/* All mutexes are required for schema access. Make sure we hold them. */
|
/* All mutexes are required for schema access. Make sure we hold them. */
|
||||||
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
||||||
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
||||||
@ -387,7 +384,7 @@ Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
|
|||||||
assert( pSchema );
|
assert( pSchema );
|
||||||
if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
|
if( zDb && sqlite3StrICmp(zDb, db->aDb[j].zName) ) continue;
|
||||||
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
||||||
p = sqlite3HashFind(&pSchema->idxHash, zName, nName);
|
p = sqlite3HashFind(&pSchema->idxHash, zName);
|
||||||
if( p ) break;
|
if( p ) break;
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
@ -415,13 +412,11 @@ static void freeIndex(sqlite3 *db, Index *p){
|
|||||||
*/
|
*/
|
||||||
void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
|
void sqlite3UnlinkAndDeleteIndex(sqlite3 *db, int iDb, const char *zIdxName){
|
||||||
Index *pIndex;
|
Index *pIndex;
|
||||||
int len;
|
|
||||||
Hash *pHash;
|
Hash *pHash;
|
||||||
|
|
||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
pHash = &db->aDb[iDb].pSchema->idxHash;
|
pHash = &db->aDb[iDb].pSchema->idxHash;
|
||||||
len = sqlite3Strlen30(zIdxName);
|
pIndex = sqlite3HashInsert(pHash, zIdxName, 0);
|
||||||
pIndex = sqlite3HashInsert(pHash, zIdxName, len, 0);
|
|
||||||
if( ALWAYS(pIndex) ){
|
if( ALWAYS(pIndex) ){
|
||||||
if( pIndex->pTable->pIndex==pIndex ){
|
if( pIndex->pTable->pIndex==pIndex ){
|
||||||
pIndex->pTable->pIndex = pIndex->pNext;
|
pIndex->pTable->pIndex = pIndex->pNext;
|
||||||
@ -581,7 +576,7 @@ void sqlite3DeleteTable(sqlite3 *db, Table *pTable){
|
|||||||
if( !db || db->pnBytesFreed==0 ){
|
if( !db || db->pnBytesFreed==0 ){
|
||||||
char *zName = pIndex->zName;
|
char *zName = pIndex->zName;
|
||||||
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
|
TESTONLY ( Index *pOld = ) sqlite3HashInsert(
|
||||||
&pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0
|
&pIndex->pSchema->idxHash, zName, 0
|
||||||
);
|
);
|
||||||
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
||||||
assert( pOld==pIndex || pOld==0 );
|
assert( pOld==pIndex || pOld==0 );
|
||||||
@ -624,8 +619,7 @@ void sqlite3UnlinkAndDeleteTable(sqlite3 *db, int iDb, const char *zTabName){
|
|||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
|
testcase( zTabName[0]==0 ); /* Zero-length table names are allowed */
|
||||||
pDb = &db->aDb[iDb];
|
pDb = &db->aDb[iDb];
|
||||||
p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName,
|
p = sqlite3HashInsert(&pDb->pSchema->tblHash, zTabName, 0);
|
||||||
sqlite3Strlen30(zTabName),0);
|
|
||||||
sqlite3DeleteTable(db, p);
|
sqlite3DeleteTable(db, p);
|
||||||
db->flags |= SQLITE_InternChanges;
|
db->flags |= SQLITE_InternChanges;
|
||||||
}
|
}
|
||||||
@ -1947,8 +1941,7 @@ void sqlite3EndTable(
|
|||||||
Table *pOld;
|
Table *pOld;
|
||||||
Schema *pSchema = p->pSchema;
|
Schema *pSchema = p->pSchema;
|
||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName,
|
pOld = sqlite3HashInsert(&pSchema->tblHash, p->zName, p);
|
||||||
sqlite3Strlen30(p->zName),p);
|
|
||||||
if( pOld ){
|
if( pOld ){
|
||||||
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
|
assert( p==pOld ); /* Malloc must have failed inside HashInsert() */
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
@ -2598,7 +2591,7 @@ void sqlite3CreateForeignKey(
|
|||||||
|
|
||||||
assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
|
assert( sqlite3SchemaMutexHeld(db, 0, p->pSchema) );
|
||||||
pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
|
pNextTo = (FKey *)sqlite3HashInsert(&p->pSchema->fkeyHash,
|
||||||
pFKey->zTo, sqlite3Strlen30(pFKey->zTo), (void *)pFKey
|
pFKey->zTo, (void *)pFKey
|
||||||
);
|
);
|
||||||
if( pNextTo==pFKey ){
|
if( pNextTo==pFKey ){
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
@ -3146,8 +3139,7 @@ Index *sqlite3CreateIndex(
|
|||||||
Index *p;
|
Index *p;
|
||||||
assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
assert( sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) );
|
||||||
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
|
p = sqlite3HashInsert(&pIndex->pSchema->idxHash,
|
||||||
pIndex->zName, sqlite3Strlen30(pIndex->zName),
|
pIndex->zName, pIndex);
|
||||||
pIndex);
|
|
||||||
if( p ){
|
if( p ){
|
||||||
assert( p==pIndex ); /* Malloc must have failed */
|
assert( p==pIndex ); /* Malloc must have failed */
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
|
@ -154,11 +154,11 @@ static CollSeq *findCollSeqEntry(
|
|||||||
int create /* Create a new entry if true */
|
int create /* Create a new entry if true */
|
||||||
){
|
){
|
||||||
CollSeq *pColl;
|
CollSeq *pColl;
|
||||||
int nName = sqlite3Strlen30(zName);
|
pColl = sqlite3HashFind(&db->aCollSeq, zName);
|
||||||
pColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
|
|
||||||
|
|
||||||
if( 0==pColl && create ){
|
if( 0==pColl && create ){
|
||||||
pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1 );
|
int nName = sqlite3Strlen30(zName);
|
||||||
|
pColl = sqlite3DbMallocZero(db, 3*sizeof(*pColl) + nName + 1);
|
||||||
if( pColl ){
|
if( pColl ){
|
||||||
CollSeq *pDel = 0;
|
CollSeq *pDel = 0;
|
||||||
pColl[0].zName = (char*)&pColl[3];
|
pColl[0].zName = (char*)&pColl[3];
|
||||||
@ -169,7 +169,7 @@ static CollSeq *findCollSeqEntry(
|
|||||||
pColl[2].enc = SQLITE_UTF16BE;
|
pColl[2].enc = SQLITE_UTF16BE;
|
||||||
memcpy(pColl[0].zName, zName, nName);
|
memcpy(pColl[0].zName, zName, nName);
|
||||||
pColl[0].zName[nName] = 0;
|
pColl[0].zName[nName] = 0;
|
||||||
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, nName, pColl);
|
pDel = sqlite3HashInsert(&db->aCollSeq, pColl[0].zName, pColl);
|
||||||
|
|
||||||
/* If a malloc() failure occurred in sqlite3HashInsert(), it will
|
/* If a malloc() failure occurred in sqlite3HashInsert(), it will
|
||||||
** return the pColl pointer to be deleted (because it wasn't added
|
** return the pColl pointer to be deleted (because it wasn't added
|
||||||
|
@ -659,8 +659,7 @@ static void fkScanChildren(
|
|||||||
** table).
|
** table).
|
||||||
*/
|
*/
|
||||||
FKey *sqlite3FkReferences(Table *pTab){
|
FKey *sqlite3FkReferences(Table *pTab){
|
||||||
int nName = sqlite3Strlen30(pTab->zName);
|
return (FKey *)sqlite3HashFind(&pTab->pSchema->fkeyHash, pTab->zName);
|
||||||
return (FKey *)sqlite3HashFind(&pTab->pSchema->fkeyHash, pTab->zName, nName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -1338,7 +1337,7 @@ void sqlite3FkDelete(sqlite3 *db, Table *pTab){
|
|||||||
}else{
|
}else{
|
||||||
void *p = (void *)pFKey->pNextTo;
|
void *p = (void *)pFKey->pNextTo;
|
||||||
const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
|
const char *z = (p ? pFKey->pNextTo->zTo : pFKey->zTo);
|
||||||
sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, sqlite3Strlen30(z), p);
|
sqlite3HashInsert(&pTab->pSchema->fkeyHash, z, p);
|
||||||
}
|
}
|
||||||
if( pFKey->pNextTo ){
|
if( pFKey->pNextTo ){
|
||||||
pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
|
pFKey->pNextTo->pPrevTo = pFKey->pPrevTo;
|
||||||
|
66
src/hash.c
66
src/hash.c
@ -52,12 +52,11 @@ void sqlite3HashClear(Hash *pH){
|
|||||||
/*
|
/*
|
||||||
** The hashing function.
|
** The hashing function.
|
||||||
*/
|
*/
|
||||||
static unsigned int strHash(const char *z, int nKey){
|
static unsigned int strHash(const char *z){
|
||||||
unsigned int h = 0;
|
unsigned int h = 0;
|
||||||
assert( nKey>=0 );
|
unsigned char c;
|
||||||
while( nKey > 0 ){
|
while( (c = (unsigned char)*z++)!=0 ){
|
||||||
h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
|
h = (h<<3) ^ h ^ sqlite3UpperToLower[c];
|
||||||
nKey--;
|
|
||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
@ -129,7 +128,7 @@ static int rehash(Hash *pH, unsigned int new_size){
|
|||||||
pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
|
pH->htsize = new_size = sqlite3MallocSize(new_ht)/sizeof(struct _ht);
|
||||||
memset(new_ht, 0, new_size*sizeof(struct _ht));
|
memset(new_ht, 0, new_size*sizeof(struct _ht));
|
||||||
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
|
for(elem=pH->first, pH->first=0; elem; elem = next_elem){
|
||||||
unsigned int h = strHash(elem->pKey, elem->nKey) % new_size;
|
unsigned int h = strHash(elem->pKey) % new_size;
|
||||||
next_elem = elem->next;
|
next_elem = elem->next;
|
||||||
insertElement(pH, &new_ht[h], elem);
|
insertElement(pH, &new_ht[h], elem);
|
||||||
}
|
}
|
||||||
@ -137,28 +136,33 @@ static int rehash(Hash *pH, unsigned int new_size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* This function (for internal use only) locates an element in an
|
/* This function (for internal use only) locates an element in an
|
||||||
** hash table that matches the given key. The hash for this key has
|
** hash table that matches the given key. The hash for this key is
|
||||||
** already been computed and is passed as the 4th parameter.
|
** also computed and returned in the *pH parameter.
|
||||||
*/
|
*/
|
||||||
static HashElem *findElementGivenHash(
|
static HashElem *findElementWithHash(
|
||||||
const Hash *pH, /* The pH to be searched */
|
const Hash *pH, /* The pH to be searched */
|
||||||
const char *pKey, /* The key we are searching for */
|
const char *pKey, /* The key we are searching for */
|
||||||
int nKey, /* Bytes in key (not counting zero terminator) */
|
unsigned int *pHash /* Write the hash value here */
|
||||||
unsigned int h /* The hash for this key. */
|
|
||||||
){
|
){
|
||||||
HashElem *elem; /* Used to loop thru the element list */
|
HashElem *elem; /* Used to loop thru the element list */
|
||||||
int count; /* Number of elements left to test */
|
int count; /* Number of elements left to test */
|
||||||
|
unsigned int h; /* The computed hash */
|
||||||
|
|
||||||
if( pH->ht ){
|
if( pH->ht ){
|
||||||
struct _ht *pEntry = &pH->ht[h];
|
struct _ht *pEntry;
|
||||||
|
h = strHash(pKey) % pH->htsize;
|
||||||
|
pEntry = &pH->ht[h];
|
||||||
elem = pEntry->chain;
|
elem = pEntry->chain;
|
||||||
count = pEntry->count;
|
count = pEntry->count;
|
||||||
}else{
|
}else{
|
||||||
|
h = 0;
|
||||||
elem = pH->first;
|
elem = pH->first;
|
||||||
count = pH->count;
|
count = pH->count;
|
||||||
}
|
}
|
||||||
while( count-- && ALWAYS(elem) ){
|
*pHash = h;
|
||||||
if( elem->nKey==nKey && sqlite3StrNICmp(elem->pKey,pKey,nKey)==0 ){
|
while( count-- ){
|
||||||
|
assert( elem!=0 );
|
||||||
|
if( sqlite3StrICmp(elem->pKey,pKey)==0 ){
|
||||||
return elem;
|
return elem;
|
||||||
}
|
}
|
||||||
elem = elem->next;
|
elem = elem->next;
|
||||||
@ -201,26 +205,20 @@ static void removeElementGivenHash(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Attempt to locate an element of the hash table pH with a key
|
/* Attempt to locate an element of the hash table pH with a key
|
||||||
** that matches pKey,nKey. Return the data for this element if it is
|
** that matches pKey. Return the data for this element if it is
|
||||||
** found, or NULL if there is no match.
|
** found, or NULL if there is no match.
|
||||||
*/
|
*/
|
||||||
void *sqlite3HashFind(const Hash *pH, const char *pKey, int nKey){
|
void *sqlite3HashFind(const Hash *pH, const char *pKey){
|
||||||
HashElem *elem; /* The element that matches key */
|
HashElem *elem; /* The element that matches key */
|
||||||
unsigned int h; /* A hash on key */
|
unsigned int h; /* A hash on key */
|
||||||
|
|
||||||
assert( pH!=0 );
|
assert( pH!=0 );
|
||||||
assert( pKey!=0 );
|
assert( pKey!=0 );
|
||||||
assert( nKey>=0 );
|
elem = findElementWithHash(pH, pKey, &h);
|
||||||
if( pH->ht ){
|
|
||||||
h = strHash(pKey, nKey) % pH->htsize;
|
|
||||||
}else{
|
|
||||||
h = 0;
|
|
||||||
}
|
|
||||||
elem = findElementGivenHash(pH, pKey, nKey, h);
|
|
||||||
return elem ? elem->data : 0;
|
return elem ? elem->data : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Insert an element into the hash table pH. The key is pKey,nKey
|
/* Insert an element into the hash table pH. The key is pKey
|
||||||
** and the data is "data".
|
** and the data is "data".
|
||||||
**
|
**
|
||||||
** If no element exists with a matching key, then a new
|
** If no element exists with a matching key, then a new
|
||||||
@ -234,20 +232,14 @@ void *sqlite3HashFind(const Hash *pH, const char *pKey, int nKey){
|
|||||||
** If the "data" parameter to this function is NULL, then the
|
** If the "data" parameter to this function is NULL, then the
|
||||||
** element corresponding to "key" is removed from the hash table.
|
** element corresponding to "key" is removed from the hash table.
|
||||||
*/
|
*/
|
||||||
void *sqlite3HashInsert(Hash *pH, const char *pKey, int nKey, void *data){
|
void *sqlite3HashInsert(Hash *pH, const char *pKey, void *data){
|
||||||
unsigned int h; /* the hash of the key modulo hash table size */
|
unsigned int h; /* the hash of the key modulo hash table size */
|
||||||
HashElem *elem; /* Used to loop thru the element list */
|
HashElem *elem; /* Used to loop thru the element list */
|
||||||
HashElem *new_elem; /* New element added to the pH */
|
HashElem *new_elem; /* New element added to the pH */
|
||||||
|
|
||||||
assert( pH!=0 );
|
assert( pH!=0 );
|
||||||
assert( pKey!=0 );
|
assert( pKey!=0 );
|
||||||
assert( nKey>=0 );
|
elem = findElementWithHash(pH,pKey,&h);
|
||||||
if( pH->htsize ){
|
|
||||||
h = strHash(pKey, nKey) % pH->htsize;
|
|
||||||
}else{
|
|
||||||
h = 0;
|
|
||||||
}
|
|
||||||
elem = findElementGivenHash(pH,pKey,nKey,h);
|
|
||||||
if( elem ){
|
if( elem ){
|
||||||
void *old_data = elem->data;
|
void *old_data = elem->data;
|
||||||
if( data==0 ){
|
if( data==0 ){
|
||||||
@ -255,7 +247,6 @@ void *sqlite3HashInsert(Hash *pH, const char *pKey, int nKey, void *data){
|
|||||||
}else{
|
}else{
|
||||||
elem->data = data;
|
elem->data = data;
|
||||||
elem->pKey = pKey;
|
elem->pKey = pKey;
|
||||||
assert(nKey==elem->nKey);
|
|
||||||
}
|
}
|
||||||
return old_data;
|
return old_data;
|
||||||
}
|
}
|
||||||
@ -263,19 +254,14 @@ void *sqlite3HashInsert(Hash *pH, const char *pKey, int nKey, void *data){
|
|||||||
new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
|
new_elem = (HashElem*)sqlite3Malloc( sizeof(HashElem) );
|
||||||
if( new_elem==0 ) return data;
|
if( new_elem==0 ) return data;
|
||||||
new_elem->pKey = pKey;
|
new_elem->pKey = pKey;
|
||||||
new_elem->nKey = nKey;
|
|
||||||
new_elem->data = data;
|
new_elem->data = data;
|
||||||
pH->count++;
|
pH->count++;
|
||||||
if( pH->count>=10 && pH->count > 2*pH->htsize ){
|
if( pH->count>=10 && pH->count > 2*pH->htsize ){
|
||||||
if( rehash(pH, pH->count*2) ){
|
if( rehash(pH, pH->count*2) ){
|
||||||
assert( pH->htsize>0 );
|
assert( pH->htsize>0 );
|
||||||
h = strHash(pKey, nKey) % pH->htsize;
|
h = strHash(pKey) % pH->htsize;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if( pH->ht ){
|
insertElement(pH, pH->ht ? &pH->ht[h] : 0, new_elem);
|
||||||
insertElement(pH, &pH->ht[h], new_elem);
|
|
||||||
}else{
|
|
||||||
insertElement(pH, 0, new_elem);
|
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -59,15 +59,15 @@ struct Hash {
|
|||||||
struct HashElem {
|
struct HashElem {
|
||||||
HashElem *next, *prev; /* Next and previous elements in the table */
|
HashElem *next, *prev; /* Next and previous elements in the table */
|
||||||
void *data; /* Data associated with this element */
|
void *data; /* Data associated with this element */
|
||||||
const char *pKey; int nKey; /* Key associated with this element */
|
const char *pKey; /* Key associated with this element */
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Access routines. To delete, insert a NULL pointer.
|
** Access routines. To delete, insert a NULL pointer.
|
||||||
*/
|
*/
|
||||||
void sqlite3HashInit(Hash*);
|
void sqlite3HashInit(Hash*);
|
||||||
void *sqlite3HashInsert(Hash*, const char *pKey, int nKey, void *pData);
|
void *sqlite3HashInsert(Hash*, const char *pKey, void *pData);
|
||||||
void *sqlite3HashFind(const Hash*, const char *pKey, int nKey);
|
void *sqlite3HashFind(const Hash*, const char *pKey);
|
||||||
void sqlite3HashClear(Hash*);
|
void sqlite3HashClear(Hash*);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1998,7 +1998,6 @@ static int createCollation(
|
|||||||
){
|
){
|
||||||
CollSeq *pColl;
|
CollSeq *pColl;
|
||||||
int enc2;
|
int enc2;
|
||||||
int nName = sqlite3Strlen30(zName);
|
|
||||||
|
|
||||||
assert( sqlite3_mutex_held(db->mutex) );
|
assert( sqlite3_mutex_held(db->mutex) );
|
||||||
|
|
||||||
@ -2037,7 +2036,7 @@ static int createCollation(
|
|||||||
** to be called.
|
** to be called.
|
||||||
*/
|
*/
|
||||||
if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
|
if( (pColl->enc & ~SQLITE_UTF16_ALIGNED)==enc2 ){
|
||||||
CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName, nName);
|
CollSeq *aColl = sqlite3HashFind(&db->aCollSeq, zName);
|
||||||
int j;
|
int j;
|
||||||
for(j=0; j<3; j++){
|
for(j=0; j<3; j++){
|
||||||
CollSeq *p = &aColl[j];
|
CollSeq *p = &aColl[j];
|
||||||
|
@ -180,8 +180,7 @@ void sqlite3BeginTrigger(
|
|||||||
goto trigger_cleanup;
|
goto trigger_cleanup;
|
||||||
}
|
}
|
||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),
|
if( sqlite3HashFind(&(db->aDb[iDb].pSchema->trigHash),zName) ){
|
||||||
zName, sqlite3Strlen30(zName)) ){
|
|
||||||
if( !noErr ){
|
if( !noErr ){
|
||||||
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
sqlite3ErrorMsg(pParse, "trigger %T already exists", pName);
|
||||||
}else{
|
}else{
|
||||||
@ -324,13 +323,12 @@ void sqlite3FinishTrigger(
|
|||||||
Trigger *pLink = pTrig;
|
Trigger *pLink = pTrig;
|
||||||
Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
|
Hash *pHash = &db->aDb[iDb].pSchema->trigHash;
|
||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
pTrig = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), pTrig);
|
pTrig = sqlite3HashInsert(pHash, zName, pTrig);
|
||||||
if( pTrig ){
|
if( pTrig ){
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
}else if( pLink->pSchema==pLink->pTabSchema ){
|
}else if( pLink->pSchema==pLink->pTabSchema ){
|
||||||
Table *pTab;
|
Table *pTab;
|
||||||
int n = sqlite3Strlen30(pLink->table);
|
pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table);
|
||||||
pTab = sqlite3HashFind(&pLink->pTabSchema->tblHash, pLink->table, n);
|
|
||||||
assert( pTab!=0 );
|
assert( pTab!=0 );
|
||||||
pLink->pNext = pTab->pTrigger;
|
pLink->pNext = pTab->pTrigger;
|
||||||
pTab->pTrigger = pLink;
|
pTab->pTrigger = pLink;
|
||||||
@ -489,7 +487,6 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){
|
|||||||
int i;
|
int i;
|
||||||
const char *zDb;
|
const char *zDb;
|
||||||
const char *zName;
|
const char *zName;
|
||||||
int nName;
|
|
||||||
sqlite3 *db = pParse->db;
|
sqlite3 *db = pParse->db;
|
||||||
|
|
||||||
if( db->mallocFailed ) goto drop_trigger_cleanup;
|
if( db->mallocFailed ) goto drop_trigger_cleanup;
|
||||||
@ -500,13 +497,12 @@ void sqlite3DropTrigger(Parse *pParse, SrcList *pName, int noErr){
|
|||||||
assert( pName->nSrc==1 );
|
assert( pName->nSrc==1 );
|
||||||
zDb = pName->a[0].zDatabase;
|
zDb = pName->a[0].zDatabase;
|
||||||
zName = pName->a[0].zName;
|
zName = pName->a[0].zName;
|
||||||
nName = sqlite3Strlen30(zName);
|
|
||||||
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
assert( zDb!=0 || sqlite3BtreeHoldsAllMutexes(db) );
|
||||||
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
for(i=OMIT_TEMPDB; i<db->nDb; i++){
|
||||||
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
int j = (i<2) ? i^1 : i; /* Search TEMP before MAIN */
|
||||||
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
if( zDb && sqlite3StrICmp(db->aDb[j].zName, zDb) ) continue;
|
||||||
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
assert( sqlite3SchemaMutexHeld(db, j, 0) );
|
||||||
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName, nName);
|
pTrigger = sqlite3HashFind(&(db->aDb[j].pSchema->trigHash), zName);
|
||||||
if( pTrigger ) break;
|
if( pTrigger ) break;
|
||||||
}
|
}
|
||||||
if( !pTrigger ){
|
if( !pTrigger ){
|
||||||
@ -529,8 +525,7 @@ drop_trigger_cleanup:
|
|||||||
** is set on.
|
** is set on.
|
||||||
*/
|
*/
|
||||||
static Table *tableOfTrigger(Trigger *pTrigger){
|
static Table *tableOfTrigger(Trigger *pTrigger){
|
||||||
int n = sqlite3Strlen30(pTrigger->table);
|
return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table);
|
||||||
return sqlite3HashFind(&pTrigger->pTabSchema->tblHash, pTrigger->table, n);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -602,7 +597,7 @@ void sqlite3UnlinkAndDeleteTrigger(sqlite3 *db, int iDb, const char *zName){
|
|||||||
|
|
||||||
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
|
||||||
pHash = &(db->aDb[iDb].pSchema->trigHash);
|
pHash = &(db->aDb[iDb].pSchema->trigHash);
|
||||||
pTrigger = sqlite3HashInsert(pHash, zName, sqlite3Strlen30(zName), 0);
|
pTrigger = sqlite3HashInsert(pHash, zName, 0);
|
||||||
if( ALWAYS(pTrigger) ){
|
if( ALWAYS(pTrigger) ){
|
||||||
if( pTrigger->pSchema==pTrigger->pTabSchema ){
|
if( pTrigger->pSchema==pTrigger->pTabSchema ){
|
||||||
Table *pTab = tableOfTrigger(pTrigger);
|
Table *pTab = tableOfTrigger(pTrigger);
|
||||||
|
11
src/vtab.c
11
src/vtab.c
@ -43,7 +43,7 @@ static int createModule(
|
|||||||
|
|
||||||
sqlite3_mutex_enter(db->mutex);
|
sqlite3_mutex_enter(db->mutex);
|
||||||
nName = sqlite3Strlen30(zName);
|
nName = sqlite3Strlen30(zName);
|
||||||
if( sqlite3HashFind(&db->aModule, zName, nName) ){
|
if( sqlite3HashFind(&db->aModule, zName) ){
|
||||||
rc = SQLITE_MISUSE_BKPT;
|
rc = SQLITE_MISUSE_BKPT;
|
||||||
}else{
|
}else{
|
||||||
Module *pMod;
|
Module *pMod;
|
||||||
@ -56,7 +56,7 @@ static int createModule(
|
|||||||
pMod->pModule = pModule;
|
pMod->pModule = pModule;
|
||||||
pMod->pAux = pAux;
|
pMod->pAux = pAux;
|
||||||
pMod->xDestroy = xDestroy;
|
pMod->xDestroy = xDestroy;
|
||||||
pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,nName,(void*)pMod);
|
pDel = (Module *)sqlite3HashInsert(&db->aModule,zCopy,(void*)pMod);
|
||||||
assert( pDel==0 || pDel==pMod );
|
assert( pDel==0 || pDel==pMod );
|
||||||
if( pDel ){
|
if( pDel ){
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
@ -425,9 +425,8 @@ void sqlite3VtabFinishParse(Parse *pParse, Token *pEnd){
|
|||||||
Table *pOld;
|
Table *pOld;
|
||||||
Schema *pSchema = pTab->pSchema;
|
Schema *pSchema = pTab->pSchema;
|
||||||
const char *zName = pTab->zName;
|
const char *zName = pTab->zName;
|
||||||
int nName = sqlite3Strlen30(zName);
|
|
||||||
assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
|
assert( sqlite3SchemaMutexHeld(db, 0, pSchema) );
|
||||||
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, nName, pTab);
|
pOld = sqlite3HashInsert(&pSchema->tblHash, zName, pTab);
|
||||||
if( pOld ){
|
if( pOld ){
|
||||||
db->mallocFailed = 1;
|
db->mallocFailed = 1;
|
||||||
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
|
assert( pTab==pOld ); /* Malloc must have failed inside HashInsert() */
|
||||||
@ -593,7 +592,7 @@ int sqlite3VtabCallConnect(Parse *pParse, Table *pTab){
|
|||||||
|
|
||||||
/* Locate the required virtual table module */
|
/* Locate the required virtual table module */
|
||||||
zMod = pTab->azModuleArg[0];
|
zMod = pTab->azModuleArg[0];
|
||||||
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
|
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
|
||||||
|
|
||||||
if( !pMod ){
|
if( !pMod ){
|
||||||
const char *zModule = pTab->azModuleArg[0];
|
const char *zModule = pTab->azModuleArg[0];
|
||||||
@ -661,7 +660,7 @@ int sqlite3VtabCallCreate(sqlite3 *db, int iDb, const char *zTab, char **pzErr){
|
|||||||
|
|
||||||
/* Locate the required virtual table module */
|
/* Locate the required virtual table module */
|
||||||
zMod = pTab->azModuleArg[0];
|
zMod = pTab->azModuleArg[0];
|
||||||
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod, sqlite3Strlen30(zMod));
|
pMod = (Module*)sqlite3HashFind(&db->aModule, zMod);
|
||||||
|
|
||||||
/* If the module has been registered and includes a Create method,
|
/* If the module has been registered and includes a Create method,
|
||||||
** invoke it now. If the module has not been registered, return an
|
** invoke it now. If the module has not been registered, return an
|
||||||
|
Loading…
Reference in New Issue
Block a user