Speed up parser by allocating more space for its statements initially.
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Deukhoofd 2019-09-21 09:52:22 +02:00
parent 0d59a1d029
commit 74d23530a1
Signed by: Deukhoofd
GPG Key ID: ADF2E9256009EDCE
1 changed files with 6 additions and 3 deletions

View File

@ -8,16 +8,19 @@
namespace Porygon::Parser {
ParsedScriptStatement *Parser::Parse() {
vector<const ParsedStatement *> statements;
vector<const ParsedStatement *> statements(this->_tokens.size());
size_t current = 0;
while (this->_position < this->_tokens.size()) {
auto next = this->Next();
if (next->GetKind() == TokenKind::EndOfFile) {
break;
}
statements.push_back(this->ParseStatement(next));
statements[current] = this -> ParseStatement(next);
current++;
}
statements.resize(current);
auto end = 0;
if (statements.size() > 0){
if (current > 0){
end = statements.back()->GetEndPosition();
}
return new ParsedScriptStatement(statements, 0, end);