diff options
author | Itamar <itamar8910@gmail.com> | 2021-07-13 20:37:28 +0300 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2021-07-13 23:20:09 +0200 |
commit | eb6a15d52bea353a63577f14ce32aeee2b80a0b0 (patch) | |
tree | 0982cbba63adc58dcbdd56add9bb3b9587a2c3d3 /Userland/Libraries | |
parent | 2c41e89d08ad6b41eb960e53b06dafe1f5d905cc (diff) | |
download | serenity-eb6a15d52bea353a63577f14ce32aeee2b80a0b0.zip |
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.
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.cpp | 6 | ||||
-rw-r--r-- | Userland/Libraries/LibCpp/Parser.h | 4 |
2 files changed, 7 insertions, 3 deletions
diff --git a/Userland/Libraries/LibCpp/Parser.cpp b/Userland/Libraries/LibCpp/Parser.cpp index 22f4ce4fed..3155d20b31 100644 --- a/Userland/Libraries/LibCpp/Parser.cpp +++ b/Userland/Libraries/LibCpp/Parser.cpp @@ -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() diff --git a/Userland/Libraries/LibCpp/Parser.h b/Userland/Libraries/LibCpp/Parser.h index 665d8f71ee..b2a5721db5 100644 --- a/Userland/Libraries/LibCpp/Parser.h +++ b/Userland/Libraries/LibCpp/Parser.h @@ -33,7 +33,7 @@ public: String text_of_node(const ASTNode&) const; StringView text_of_token(const Cpp::Token& token) const; void print_tokens() const; - const Vector<String>& errors() const { return m_state.errors; } + const Vector<String>& errors() const { return m_errors; } const Preprocessor::Definitions& preprocessor_definitions() const { return m_preprocessor_definitions; } struct TodoEntry { @@ -147,7 +147,6 @@ private: struct State { size_t token_index { 0 }; - Vector<String> errors; NonnullRefPtrVector<ASTNode> nodes; }; @@ -200,6 +199,7 @@ private: State m_state; Vector<State> m_saved_states; RefPtr<TranslationUnit> m_root_node; + Vector<String> m_errors; Vector<TokenAndPreprocessorDefinition> m_replaced_preprocessor_tokens; }; |