Speed up parser by allocating more space for its statements initially.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -8,16 +8,19 @@
|
|||||||
|
|
||||||
namespace Porygon::Parser {
|
namespace Porygon::Parser {
|
||||||
ParsedScriptStatement *Parser::Parse() {
|
ParsedScriptStatement *Parser::Parse() {
|
||||||
vector<const ParsedStatement *> statements;
|
vector<const ParsedStatement *> statements(this->_tokens.size());
|
||||||
|
size_t current = 0;
|
||||||
while (this->_position < this->_tokens.size()) {
|
while (this->_position < this->_tokens.size()) {
|
||||||
auto next = this->Next();
|
auto next = this->Next();
|
||||||
if (next->GetKind() == TokenKind::EndOfFile) {
|
if (next->GetKind() == TokenKind::EndOfFile) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
statements.push_back(this->ParseStatement(next));
|
statements[current] = this -> ParseStatement(next);
|
||||||
|
current++;
|
||||||
}
|
}
|
||||||
|
statements.resize(current);
|
||||||
auto end = 0;
|
auto end = 0;
|
||||||
if (statements.size() > 0){
|
if (current > 0){
|
||||||
end = statements.back()->GetEndPosition();
|
end = statements.back()->GetEndPosition();
|
||||||
}
|
}
|
||||||
return new ParsedScriptStatement(statements, 0, end);
|
return new ParsedScriptStatement(statements, 0, end);
|
||||||
|
|||||||
Reference in New Issue
Block a user