1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibCpp: Only store error messages for the main parser state

There's no need to store parser error messages for states with
depth > 0, as they will eventually be popped from the states stack and
their error messages will never be displayed to the user.

Profiling shows that this change reduces the % of backtraces that
contain the store_state & load_state functions from ~95% to ~70%.

Empirically this change reduces the time it takes on my machine for the
c++ language server to handle a file that #includes <LibGUI/Widget.h>
from ~14sec to ~4sec.
This commit is contained in:
Itamar 2021-07-13 20:37:28 +03:00 committed by Andreas Kling
parent 2c41e89d08
commit eb6a15d52b
2 changed files with 7 additions and 3 deletions

View file

@ -894,6 +894,10 @@ Vector<Token> Parser::tokens_in_range(Position start, Position end) const
void Parser::error(StringView message)
{
LOG_SCOPE();
if (!m_saved_states.is_empty())
return;
if (message.is_null() || message.is_empty())
message = "<empty>";
String formatted_message;
@ -907,7 +911,7 @@ void Parser::error(StringView message)
m_tokens[m_state.token_index].start().column);
}
m_state.errors.append(formatted_message);
m_errors.append(formatted_message);
}
bool Parser::match_expression()