1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-30 19:03:16 +03:00

Performance and size optimization for the sqlite3ColumnIndex() routine.

FossilOrigin-Name: a93e3fe0ee8f98a7ec0dfb2e1abf432cc9d5f9d3ad345b5db261475215d43df9
This commit is contained in:
drh
2025-02-09 19:49:46 +00:00
parent b85b7f257d
commit 3bdebaeabb
4 changed files with 23 additions and 23 deletions

View File

@ -1526,8 +1526,7 @@ void sqlite3AddColumn(Parse *pParse, Token sName, Token sType){
memcpy(z, sName.z, sName.n);
z[sName.n] = 0;
sqlite3Dequote(z);
i = sqlite3ColumnIndex(p, z);
if( i>=0 ){
if( p->nCol && sqlite3ColumnIndex(p, z)>=0 ){
sqlite3ErrorMsg(pParse, "duplicate column name: %s", z);
sqlite3DbFree(db, z);
return;

View File

@ -320,31 +320,32 @@ int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){
int sqlite3ColumnIndex(Table *pTab, const char *zCol){
int i;
u8 h;
Column *pCol;
const Column *aCol;
int nCol;
if( pTab->nCol==0 ){
return -1;
}
h = sqlite3StrIHash(zCol);
aCol = pTab->aCol;
nCol = pTab->nCol;
/* See if the aHx gives us a lucky match */
i = pTab->aHx[h % sizeof(pTab->aHx)];
assert( i<pTab->nCol );
if( pTab->aCol[i].hName==h
&& sqlite3StrICmp(pTab->aCol[i].zCnName, zCol)==0
assert( i<nCol );
if( aCol[i].hName==h
&& sqlite3StrICmp(aCol[i].zCnName, zCol)==0
){
return i;
}
pCol = pTab->aCol;
/* No lucky match from the hash table. Do a full search. */
i = 0;
while( 1 /*exit-by-break*/ ){
if( pCol->hName==h
&& sqlite3StrICmp(pCol->zCnName, zCol)==0
if( aCol[i].hName==h
&& sqlite3StrICmp(aCol[i].zCnName, zCol)==0
){
return i;
}
i++;
if( i>=pTab->nCol ) break;
pCol++;
if( i>=nCol ) break;
}
return -1;
}