Use binary search to speed up matching keywords (#191)

This commit is contained in:
Daniël Heres 2020-06-07 19:25:10 +02:00 committed by GitHub
parent af54eb02b2
commit a42121de52
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 18 deletions

View file

@ -143,10 +143,9 @@ impl Token {
}
pub fn make_word(word: &str, quote_style: Option<char>) -> Self {
let word_uppercase = word.to_uppercase();
//TODO: need to reintroduce FnvHashSet at some point .. iterating over keywords is
// not fast but I want the simplicity for now while I experiment with pluggable
// dialects
let is_keyword = quote_style == None && ALL_KEYWORDS.contains(&word_uppercase.as_str());
//TODO: validate use of a hashset (e.g. FnvHashSet) compared to using binary search
let is_keyword =
quote_style == None && ALL_KEYWORDS.binary_search(&word_uppercase.as_str()).is_ok();
Token::Word(Word {
value: word.to_string(),
quote_style,