diff options
author | Andreas Kling <kling@serenityos.org> | 2020-10-29 22:25:41 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-10-29 23:32:18 +0100 |
commit | aaf4ec62cf02f0c14f3b8ff49de118d9a899e463 (patch) | |
tree | a77c9ccc78d8254187ae4b2fa6d44c304e53ce63 | |
parent | c3a79e14834d04a492198e51f2befaefb629b2e4 (diff) | |
download | serenity-aaf4ec62cf02f0c14f3b8ff49de118d9a899e463.zip |
LanguageServers/Cpp: Avoid some unnecessary vector copies
-rw-r--r-- | DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp | 8 | ||||
-rw-r--r-- | DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h | 8 |
2 files changed, 8 insertions, 8 deletions
diff --git a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp index d09c96cd58..c56000fb19 100644 --- a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp +++ b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.cpp @@ -32,7 +32,7 @@ namespace LanguageServers::Cpp { -Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, GUI::TextPosition autocomplete_position) +Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, const GUI::TextPosition& autocomplete_position) { auto lines = code.split('\n', true); Lexer lexer(code); @@ -53,12 +53,12 @@ Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, G return suggestions; } -String AutoComplete::text_of_token(const Vector<String> lines, const Cpp::Token& token) +String AutoComplete::text_of_token(const Vector<String>& lines, const Cpp::Token& token) { return lines[token.m_start.line].substring(token.m_start.column, token.m_end.column - token.m_start.column + 1); } -Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& tokens, GUI::TextPosition position) +Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& tokens, const GUI::TextPosition& position) { for (size_t token_index = 0; token_index < tokens.size(); ++token_index) { auto& token = tokens[token_index]; @@ -71,7 +71,7 @@ Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& token return {}; } -Vector<AutoCompleteResponse> AutoComplete::identifier_prefixes(const Vector<String> lines, const Vector<Cpp::Token>& tokens, size_t target_token_index) +Vector<AutoCompleteResponse> AutoComplete::identifier_prefixes(const Vector<String>& lines, const Vector<Cpp::Token>& tokens, size_t target_token_index) { auto partial_input = text_of_token(lines, tokens[target_token_index]); Vector<AutoCompleteResponse> suggestions; diff --git a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h index d0b772b0ad..0ee328b5b7 100644 --- a/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h +++ b/DevTools/HackStudio/LanguageServers/Cpp/AutoComplete.h @@ -41,12 +41,12 @@ class AutoComplete { public: AutoComplete() = delete; - static Vector<AutoCompleteResponse> get_suggestions(const String& code, GUI::TextPosition autocomplete_position); + static Vector<AutoCompleteResponse> get_suggestions(const String& code, const GUI::TextPosition& autocomplete_position); private: - static Optional<size_t> token_in_position(const Vector<Cpp::Token>&, GUI::TextPosition); - static String text_of_token(const Vector<String> lines, const Cpp::Token&); - static Vector<AutoCompleteResponse> identifier_prefixes(const Vector<String> lines, const Vector<Cpp::Token>&, size_t target_token_index); + static Optional<size_t> token_in_position(const Vector<Cpp::Token>&, const GUI::TextPosition&); + static String text_of_token(const Vector<String>& lines, const Cpp::Token&); + static Vector<AutoCompleteResponse> identifier_prefixes(const Vector<String>& lines, const Vector<Cpp::Token>&, size_t target_token_index); }; } |