From 74d23530a1821df199388e94ea2402de482f65b6 Mon Sep 17 00:00:00 2001 From: Deukhoofd Date: Sat, 21 Sep 2019 09:52:22 +0200 Subject: [PATCH] Speed up parser by allocating more space for its statements initially. --- src/Parser/Parser.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index d54c143..8140dae 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -8,16 +8,19 @@ namespace Porygon::Parser { ParsedScriptStatement *Parser::Parse() { - vector statements; + vector 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);