aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
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/select.c
parentb85b7f257dc760768172c30d5b8d442737d7dec9 (diff)
downloadsqlite-3bdebaeabb4266be82ad1ab06fd5e901f5dcba72.tar.gz
sqlite-3bdebaeabb4266be82ad1ab06fd5e901f5dcba72.zip
Performance and size optimization for the sqlite3ColumnIndex() routine.
FossilOrigin-Name: a93e3fe0ee8f98a7ec0dfb2e1abf432cc9d5f9d3ad345b5db261475215d43df9
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c25
1 files changed, 13 insertions, 12 deletions
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;
}