Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit7ddf618

Browse files
committed
use binary search for keywords instead of hardcoded
1 parentceca992 commit7ddf618

File tree

1 file changed

+45
-16
lines changed

1 file changed

+45
-16
lines changed

‎jsquery_scan.l

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -183,27 +183,56 @@ yyerror(const char *message)
183183
}
184184
}
185185

186+
typedefstructkeyword
187+
{
188+
int16len;
189+
boollowercase;
190+
intval;
191+
char*keyword;
192+
} keyword;
193+
194+
static keyword keywords[] = {
195+
{2,false,IN_P,"in" },
196+
{4,true,NULL_P,"null"},
197+
{4,true,TRUE_P,"true"},
198+
{5,true,FALSE_P,"false"}
199+
};
200+
186201
staticint
187202
checkSpecialVal()
188203
{
189-
int res = STRING_P;
204+
int res = STRING_P;
205+
intdiff;
206+
keyword*StopLow = keywords,
207+
*StopHigh = keywords +lengthof(keywords),
208+
*StopMiddle;
190209

191-
if (scanstring.len ==2)
192-
{
193-
if (pg_strncasecmp("in", scanstring.val, scanstring.len) ==0)
194-
return IN_P;
195-
}
196-
elseif (scanstring.len ==4)
197-
{
198-
if (strncmp("null", scanstring.val, scanstring.len) ==0)
199-
res = NULL_P;
200-
elseif (strncmp("true", scanstring.val, scanstring.len) ==0)
201-
res = TRUE_P;
202-
}
203-
elseif (scanstring.len ==5)
210+
if (scanstring.len > keywords[lengthof(keywords) -1].len)
211+
return res;
212+
213+
while(StopLow < StopHigh)
204214
{
205-
if (strncmp("false", scanstring.val, scanstring.len) ==0)
206-
res = FALSE_P;
215+
StopMiddle = StopLow + (StopHigh - StopLow) /2;
216+
217+
if (StopMiddle->len == scanstring.len)
218+
diff =pg_strncasecmp(StopMiddle->keyword, scanstring.val, scanstring.len);
219+
else
220+
diff = StopMiddle->len - scanstring.len;
221+
222+
if (diff <0)
223+
StopLow = StopMiddle +1;
224+
elseif (diff >0)
225+
StopHigh = StopMiddle;
226+
else
227+
{
228+
if (StopMiddle->lowercase)
229+
diff =strncmp(StopMiddle->keyword, scanstring.val, scanstring.len);
230+
231+
if (diff ==0)
232+
res = StopMiddle->val;
233+
234+
break;
235+
}
207236
}
208237

209238
return res;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp