/ Check-in [5c10ccd8]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Move sqlite3HashNoCase to hash.c. (CVS 2294)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 5c10ccd8e99cab7e9f8e733dfd1447c2df1d25c1
User & Date: danielk1977 2005-01-31 12:56:44
Context
2005-01-31
23:45
Performance tweaks for sqlite3AffinityType. (CVS 2295) check-in: 32b92615 user: drh tags: trunk
12:56
Move sqlite3HashNoCase to hash.c. (CVS 2294) check-in: 5c10ccd8 user: danielk1977 tags: trunk
12:42
Assorted minor changes to speed up loading the database schema. (CVS 2293) check-in: dfbd684a user: danielk1977 tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

    18     18   **     CREATE INDEX
    19     19   **     DROP INDEX
    20     20   **     creating ID lists
    21     21   **     BEGIN TRANSACTION
    22     22   **     COMMIT
    23     23   **     ROLLBACK
    24     24   **
    25         -** $Id: build.c,v 1.302 2005/01/31 12:42:29 danielk1977 Exp $
           25  +** $Id: build.c,v 1.303 2005/01/31 12:56:44 danielk1977 Exp $
    26     26   */
    27     27   #include "sqliteInt.h"
    28     28   #include <ctype.h>
    29     29   
    30     30   /*
    31     31   ** This routine is called when a new SQL statement is beginning to
    32     32   ** be parsed.  Initialize the pParse structure as needed.
................................................................................
   849    849   void sqlite3AddNotNull(Parse *pParse, int onError){
   850    850     Table *p;
   851    851     int i;
   852    852     if( (p = pParse->pNewTable)==0 ) return;
   853    853     i = p->nCol-1;
   854    854     if( i>=0 ) p->aCol[i].notNull = onError;
   855    855   }
          856  +
          857  +/*
          858  +** Scan the column type name zType (length nType) and return the
          859  +** associated affinity type.
          860  +*/
          861  +static char sqlite3AffinityType(const char *zType, int nType){
          862  +  int n, i;
          863  +  static const struct {
          864  +    const char *zSub;  /* Keywords substring to search for */
          865  +    char nSub;         /* length of zSub */
          866  +    char affinity;     /* Affinity to return if it matches */
          867  +  } substrings[] = {
          868  +    {"INT",  3, SQLITE_AFF_INTEGER},
          869  +    {"CHAR", 4, SQLITE_AFF_TEXT},
          870  +    {"CLOB", 4, SQLITE_AFF_TEXT},
          871  +    {"TEXT", 4, SQLITE_AFF_TEXT},
          872  +    {"BLOB", 4, SQLITE_AFF_NONE},
          873  +  };
          874  +
          875  +  if( nType==0 ){
          876  +    return SQLITE_AFF_NONE;
          877  +  }
          878  +  for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){
          879  +    int c1 = substrings[i].zSub[0];
          880  +    int c2 = tolower(c1);
          881  +    int limit = nType - substrings[i].nSub;
          882  +    const char *z = substrings[i].zSub;
          883  +    for(n=0; n<=limit; n++){
          884  +      int c = zType[n];
          885  +      if( (c==c1 || c==c2)
          886  +             && 0==sqlite3StrNICmp(&zType[n], z, substrings[i].nSub) ){
          887  +        return substrings[i].affinity;
          888  +      }
          889  +    }
          890  +  }
          891  +  return SQLITE_AFF_NUMERIC;
          892  +}
   856    893   
   857    894   /*
   858    895   ** This routine is called by the parser while in the middle of
   859    896   ** parsing a CREATE TABLE statement.  The pFirst token is the first
   860    897   ** token in the sequence of tokens that describe the type of the
   861    898   ** column currently under construction.   pLast is the last token
   862    899   ** in the sequence.  Use this information to construct a string
................................................................................
  1209   1246       }
  1210   1247       pColl = 0;
  1211   1248     }
  1212   1249     return pColl;
  1213   1250   }
  1214   1251   
  1215   1252   
  1216         -
  1217         -/*
  1218         -** Scan the column type name zType (length nType) and return the
  1219         -** associated affinity type.
  1220         -*/
  1221         -static char sqlite3AffinityType(const char *zType, int nType){
  1222         -  int n, i;
  1223         -  static const struct {
  1224         -    const char *zSub;  /* Keywords substring to search for */
  1225         -    char nSub;         /* length of zSub */
  1226         -    char affinity;     /* Affinity to return if it matches */
  1227         -  } substrings[] = {
  1228         -    {"INT",  3, SQLITE_AFF_INTEGER},
  1229         -    {"CHAR", 4, SQLITE_AFF_TEXT},
  1230         -    {"CLOB", 4, SQLITE_AFF_TEXT},
  1231         -    {"TEXT", 4, SQLITE_AFF_TEXT},
  1232         -    {"BLOB", 4, SQLITE_AFF_NONE},
  1233         -  };
  1234         -
  1235         -  if( nType==0 ){
  1236         -    return SQLITE_AFF_NONE;
  1237         -  }
  1238         -  for(i=0; i<sizeof(substrings)/sizeof(substrings[0]); i++){
  1239         -    int c1 = substrings[i].zSub[0];
  1240         -    int c2 = tolower(c1);
  1241         -    int limit = nType - substrings[i].nSub;
  1242         -    const char *z = substrings[i].zSub;
  1243         -    for(n=0; n<=limit; n++){
  1244         -      int c = zType[n];
  1245         -      if( (c==c1 || c==c2)
  1246         -             && 0==sqlite3StrNICmp(&zType[n], z, substrings[i].nSub) ){
  1247         -        return substrings[i].affinity;
  1248         -      }
  1249         -    }
  1250         -  }
  1251         -  return SQLITE_AFF_NUMERIC;
  1252         -}
  1253         -
  1254   1253   /*
  1255   1254   ** Generate code that will increment the schema cookie.
  1256   1255   **
  1257   1256   ** The schema cookie is used to determine when the schema for the
  1258   1257   ** database changes.  After each schema change, the cookie value
  1259   1258   ** changes.  When a process first reads the schema it records the
  1260   1259   ** cookie.  Thereafter, whenever it goes to access the database,

Changes to src/hash.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This is the implementation of generic hash-tables
    13     13   ** used in SQLite.
    14     14   **
    15         -** $Id: hash.c,v 1.15 2004/08/20 14:08:51 drh Exp $
           15  +** $Id: hash.c,v 1.16 2005/01/31 12:56:44 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <assert.h>
    19     19   
    20     20   /* Turn bulk memory into a hash table object by initializing the
    21     21   ** fields of the Hash structure.
    22     22   **
................................................................................
    94     94   }
    95     95   #endif
    96     96   
    97     97   /*
    98     98   ** Hash and comparison functions when the mode is SQLITE_HASH_STRING
    99     99   */
   100    100   static int strHash(const void *pKey, int nKey){
   101         -  return sqlite3HashNoCase((const char*)pKey, nKey); 
          101  +  const char *z = (const char *)pKey;
          102  +  int h = 0;
          103  +  if( nKey<=0 ) nKey = strlen(z);
          104  +  while( nKey > 0  ){
          105  +    h = (h<<3) ^ h ^ sqlite3UpperToLower[(unsigned char)*z++];
          106  +    nKey--;
          107  +  }
          108  +  return h & 0x7fffffff;
   102    109   }
   103    110   static int strCompare(const void *pKey1, int n1, const void *pKey2, int n2){
   104    111     if( n1!=n2 ) return 1;
   105    112     return sqlite3StrNICmp((const char*)pKey1,(const char*)pKey2,n1);
   106    113   }
   107    114   
   108    115   /*

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.364 2005/01/29 08:32:45 danielk1977 Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.365 2005/01/31 12:56:44 danielk1977 Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Cursor support is turned off unless the SQLITE_ENABLE_CURSOR option
    21     21   ** is defined.
................................................................................
  1537   1537   int sqlite3utf16ByteLen(const void *pData, int nChar);
  1538   1538   int sqlite3utf8CharLen(const char *pData, int nByte);
  1539   1539   int sqlite3ReadUtf8(const unsigned char *);
  1540   1540   int sqlite3PutVarint(unsigned char *, u64);
  1541   1541   int sqlite3GetVarint(const unsigned char *, u64 *);
  1542   1542   int sqlite3GetVarint32(const unsigned char *, u32 *);
  1543   1543   int sqlite3VarintLen(u64 v);
  1544         -char sqlite3AffinityType(const char *, int);
  1545   1544   void sqlite3IndexAffinityStr(Vdbe *, Index *);
  1546   1545   void sqlite3TableAffinityStr(Vdbe *, Table *);
  1547   1546   char sqlite3CompareAffinity(Expr *pExpr, char aff2);
  1548   1547   int sqlite3IndexAffinityOk(Expr *pExpr, char idx_affinity);
  1549   1548   char sqlite3ExprAffinity(Expr *pExpr);
  1550   1549   int sqlite3atoi64(const char*, i64*);
  1551   1550   void sqlite3Error(sqlite3*, int, const char*,...);

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.128 2005/01/20 22:48:48 drh Exp $
           17  +** $Id: util.c,v 1.129 2005/01/31 12:56:44 danielk1977 Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__)
    24     24   #include <execinfo.h>
................................................................................
   488    488       198,199,200,201,202,203,204,205,206,207,208,209,210,211,212,213,214,215,
   489    489       216,217,218,219,220,221,222,223,224,225,226,227,228,229,230,231,232,233,
   490    490       234,235,236,237,238,239,240,241,242,243,244,245,246,247,248,249,250,251,
   491    491       252,253,254,255
   492    492   };
   493    493   #define UpperToLower sqlite3UpperToLower
   494    494   
   495         -/*
   496         -** This function computes a hash on the name of a keyword.
   497         -** Case is not significant.
   498         -*/
   499         -int sqlite3HashNoCase(const char *z, int n){
   500         -  int h = 0;
   501         -  if( n<=0 ) n = strlen(z);
   502         -  while( n > 0  ){
   503         -    h = (h<<3) ^ h ^ UpperToLower[(unsigned char)*z++];
   504         -    n--;
   505         -  }
   506         -  return h & 0x7fffffff;
   507         -}
   508         -
   509    495   /*
   510    496   ** Some systems have stricmp().  Others have strcasecmp().  Because
   511    497   ** there is no consistency, we will define our own.
   512    498   */
   513    499   int sqlite3StrICmp(const char *zLeft, const char *zRight){
   514    500     register unsigned char *a, *b;
   515    501     a = (unsigned char *)zLeft;