Replace sqlite3AffinityType() with a slightly faster version. (CVS 2296)

FossilOrigin-Name: abe9f5e81f1196f28eec628e898b2a994c4d659d
This commit is contained in:
danielk1977 2005-02-01 01:21:55 +00:00
parent 59f19c15c5
commit b3dff964bd
3 changed files with 44 additions and 35 deletions

View File

@ -1,5 +1,5 @@
C Performance\stweaks\sfor\ssqlite3AffinityType.\s(CVS\s2295)
D 2005-01-31T23:45:56
C Replace\ssqlite3AffinityType()\swith\sa\sslightly\sfaster\sversion.\s(CVS\s2296)
D 2005-02-01T01:21:55
F Makefile.in ffd81f5e926d40b457071b4de8d7c1fa18f39b5a
F Makefile.linux-gcc a9e5a0d309fa7c38e7c14d3ecf7690879d3a5457
F README a01693e454a00cc117967e3f9fdab2d4d52e9bc1
@ -31,7 +31,7 @@ F src/attach.c f78f76bc6a8e5e487ca53636e21ccba2484a9a61
F src/auth.c 18c5a0befe20f3a58a41e3ddd78f372faeeefe1f
F src/btree.c e68ae12c8b12ef9d45d58d931c36c184055a3880
F src/btree.h 74d19cf40ab49fd69abe9e4e12a6c321ad86c497
F src/build.c c09954ebeef8d7464305b4b2ff53f7fe193d7ae3
F src/build.c 7e50cb572eedf50b3f5f499bce7d5340d9b00b63
F src/cursor.c de73c00aefc4747ad59b5105cf38bbff0667922e
F src/date.c f3d1f5cd1503dabf426a198f3ebef5afbc122a7f
F src/delete.c 4b94395b52a8f7785acd71135c2ce54f3f5550b3
@ -272,7 +272,7 @@ F www/tclsqlite.tcl e73f8f8e5f20e8277619433f7970060ab01088fc
F www/vdbe.tcl 095f106d93875c94b47367384ebc870517431618
F www/version3.tcl 092a01f5ef430d2c4acc0ae558d74c4bb89638a0
F www/whentouse.tcl 3e522a06ad41992023c80ca29a048ae2331ca5bd
P 5c10ccd8e99cab7e9f8e733dfd1447c2df1d25c1
R 8e51075895dcc7f3464e186f35d155df
U drh
Z 78ca355ac379f133da207d92588fd08c
P 32b926154aaae9264359fa1e9a7189afd08b0bb7
R 8e50ba8963e4eb03424af74a3c54cd49
U danielk1977
Z e5d48140c00b6d3b721213654c5201c0

View File

@ -1 +1 @@
32b926154aaae9264359fa1e9a7189afd08b0bb7
abe9f5e81f1196f28eec628e898b2a994c4d659d

View File

@ -22,7 +22,7 @@
** COMMIT
** ROLLBACK
**
** $Id: build.c,v 1.304 2005/01/31 23:45:56 drh Exp $
** $Id: build.c,v 1.305 2005/02/01 01:21:55 danielk1977 Exp $
*/
#include "sqliteInt.h"
#include <ctype.h>
@ -857,37 +857,46 @@ void sqlite3AddNotNull(Parse *pParse, int onError){
/*
** Scan the column type name zType (length nType) and return the
** associated affinity type.
**
** This routine does a case-independent search of zType for the
** substrings in the following table. If one of the substrings is
** found, the corresponding affinity is returned. If zType contains
** more than one of the substrings, entries toward the top of
** the table take priority. For example, if zType is 'BLOBINT',
** SQLITE_AFF_INTEGER is returned.
**
** Substring | Affinity
** --------------------------------
** 'INT' | SQLITE_AFF_INTEGER
** 'CHAR' | SQLITE_AFF_TEXT
** 'CLOB' | SQLITE_AFF_TEXT
** 'TEXT' | SQLITE_AFF_TEXT
** 'BLOB' | SQLITE_AFF_NONE
**
** If none of the substrings in the above table are found,
** SQLITE_AFF_NUMERIC is returned.
*/
static char sqlite3AffinityType(const char *zType, int nType){
int n, i;
static const struct {
const char *zSub; /* Keywords substring to search for */
char nSub; /* length of zSub */
char affinity; /* Affinity to return if it matches */
} substrings[] = {
{"INT", 3, SQLITE_AFF_INTEGER},
{"CHAR", 4, SQLITE_AFF_TEXT},
{"CLOB", 4, SQLITE_AFF_TEXT},
{"TEXT", 4, SQLITE_AFF_TEXT},
{"BLOB", 4, SQLITE_AFF_NONE},
};
u32 h = 0;
char aff = SQLITE_AFF_NUMERIC;
const unsigned char *zIn = zType;
const unsigned char *zEnd = (zIn+nType);
if( nType==0 ){
return SQLITE_AFF_NONE;
}
for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){
const char *zSub = substrings[i].zSub;
int c1 = tolower(zSub[0]);
int len = substrings[i].nSub;
int limit = nType - len;
const char *z = zType;
for(n=0; n<=limit; n++, z++){
if( tolower(z[0])==c1 && 0==sqlite3StrNICmp(z, zSub, len) ){
return substrings[i].affinity;
}
while( zIn!=zEnd ){
h = (h<<8) + sqlite3UpperToLower[*zIn];
zIn++;
if ( h==0x63686172 ) aff = SQLITE_AFF_TEXT; /* CHAR */
else if( h==0x636C6F62 ) aff = SQLITE_AFF_TEXT; /* CLOB */
else if( h==0x74657874 ) aff = SQLITE_AFF_TEXT; /* TEXT */
else if( h==0x626C6F62 && aff==SQLITE_AFF_NUMERIC ){ /* BLOB */
aff = SQLITE_AFF_NONE;
}else if( (h&0x00FFFFFF)==0x00696E74 ){ /* INT */
aff = SQLITE_AFF_INTEGER;
break;
}
}
return SQLITE_AFF_NUMERIC;
return aff;
}
/*