@@ -183,27 +183,56 @@ yyerror(const char *message)
183183}
184184}
185185
186+ typedef struct keyword
187+ {
188+ int16len;
189+ bool lowercase;
190+ int val;
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+
186201static int
187202checkSpecialVal ()
188203{
189- int res = STRING_P;
204+ int res = STRING_P;
205+ int diff;
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- else if (scanstring.len ==4 )
197- {
198- if (strncmp (" null" , scanstring.val , scanstring.len ) ==0 )
199- res = NULL_P;
200- else if (strncmp (" true" , scanstring.val , scanstring.len ) ==0 )
201- res = TRUE_P;
202- }
203- else if (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+ else if (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
209238return res;