Improved performance for lexing identifiers/keywords
This commit is contained in:
parent
1cf33d5ae8
commit
23991ab2ea
|
@ -144,20 +144,21 @@ unsigned constexpr const_hash(char const *input) {
|
|||
}
|
||||
|
||||
IToken* Lexer::LexIdentifierOrKeyword(char c){
|
||||
vector<char> charVec(1, c);
|
||||
auto start = this -> Position - 1;
|
||||
auto end = start;
|
||||
while (true){
|
||||
char next = this -> Peek();
|
||||
if (next == '\0') break;
|
||||
if (isalpha(next) || next == '_'){
|
||||
this -> Next();
|
||||
charVec.push_back(next);
|
||||
end++;
|
||||
}
|
||||
else{
|
||||
break;
|
||||
}
|
||||
}
|
||||
string s = string(charVec.begin(), charVec.end());
|
||||
|
||||
string s = this -> ScriptString.substr(start, end - start + 1);
|
||||
switch (const_hash(s.c_str())){
|
||||
case const_hash("and"): return new SimpleToken(TokenKind::AndKeyword, start, 3);
|
||||
case const_hash("break"): return new SimpleToken(TokenKind::BreakKeyword, start, 5);
|
||||
|
|
Loading…
Reference in New Issue