aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2025-02-09 19:49:46 +0000
committerdrh <>2025-02-09 19:49:46 +0000
commit3bdebaeabb4266be82ad1ab06fd5e901f5dcba72 (patch)
treedbb363c4df1e76eeef8f0a87a73c7c40c4a71d96 /src
parentb85b7f257dc760768172c30d5b8d442737d7dec9 (diff)
downloadsqlite-3bdebaeabb4266be82ad1ab06fd5e901f5dcba72.tar.gz
sqlite-3bdebaeabb4266be82ad1ab06fd5e901f5dcba72.zip
Performance and size optimization for the sqlite3ColumnIndex() routine.
FossilOrigin-Name: a93e3fe0ee8f98a7ec0dfb2e1abf432cc9d5f9d3ad345b5db261475215d43df9
Diffstat (limited to 'src')
-rw-r--r--src/build.c3
-rw-r--r--src/select.c25
2 files changed, 14 insertions, 14 deletions
diff --git a/src/build.c b/src/build.c
index 7b8042529..8f64d5ec3 100644
--- a/src/build.c
+++ b/src/build.c
@@ -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;
diff --git a/src/select.c b/src/select.c
index e848c46a3..e47a9b6be 100644
--- a/src/select.c
+++ b/src/select.c
@@ -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;
}