Mike McCormack : msi: Use a binary search to find sql keywords.
Alexandre Julliard
julliard at wine.codeweavers.com
Thu Sep 7 03:45:50 CDT 2006
Module: wine
Branch: master
Commit: f9042ec9e8436f5b1614e6e9c518a8b7cd192d3d
URL: http://source.winehq.org/git/?p=wine.git;a=commit;h=f9042ec9e8436f5b1614e6e9c518a8b7cd192d3d
Author: Mike McCormack <mike at codeweavers.com>
Date: Wed Aug 30 20:07:44 2006 +0900
msi: Use a binary search to find sql keywords.
---
dlls/msi/tokenize.c | 31 +++++++++++++++++++++++--------
1 files changed, 23 insertions(+), 8 deletions(-)
diff --git a/dlls/msi/tokenize.c b/dlls/msi/tokenize.c
index fe13983..37c6b4a 100644
--- a/dlls/msi/tokenize.c
+++ b/dlls/msi/tokenize.c
@@ -39,6 +39,8 @@ struct Keyword {
int tokenType; /* The token value for this keyword */
};
+#define MAX_TOKEN_LEN 11
+
static const WCHAR ABORT_W[] = { 'A','B','O','R','T',0 };
static const WCHAR AFTER_W[] = { 'A','F','T','E','R',0 };
static const WCHAR ALTER_W[] = { 'A','L','T','E','R',0 };
@@ -264,20 +266,33 @@ static const Keyword aKeywordTable[] = {
#define KEYWORD_COUNT ( sizeof aKeywordTable/sizeof (Keyword) )
/*
+** Comparison function for binary search.
+*/
+static int compKeyword(const void *m1, const void *m2){
+ const Keyword *k1 = m1, *k2 = m2;
+
+ return strcmpiW( k1->zName, k2->zName );
+}
+
+/*
** This function looks up an identifier to determine if it is a
** keyword. If it is a keyword, the token code of that keyword is
** returned. If the input is not a keyword, TK_ID is returned.
*/
static int sqliteKeywordCode(const WCHAR *z, int n){
- UINT i;
+ WCHAR str[MAX_TOKEN_LEN+1];
+ Keyword key, *r;
- for(i=0; i<KEYWORD_COUNT; i++)
- {
- if(strncmpiW(z, aKeywordTable[i].zName, n))
- continue;
- if(lstrlenW(aKeywordTable[i].zName) == n )
- return aKeywordTable[i].tokenType;
- }
+ if( n>MAX_TOKEN_LEN )
+ return TK_ID;
+
+ memcpy( str, z, n*sizeof (WCHAR) );
+ str[n] = 0;
+ key.tokenType = 0;
+ key.zName = str;
+ r = bsearch( &key, aKeywordTable, KEYWORD_COUNT, sizeof (Keyword), compKeyword );
+ if( r )
+ return r->tokenType;
return TK_ID;
}
More information about the wine-cvs
mailing list