Improved performance for lexing identifiers/keywords

This commit is contained in:
Deukhoofd 2019-05-22 12:41:08 +02:00
parent 1cf33d5ae8
commit 23991ab2ea
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 4 additions and 3 deletions

View File

@ -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);