mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 22:17:42 +00:00
LanguageServers/Cpp: Make token_in_position() return a StringView
This avoids a whole bunch of string allocation churn.
This commit is contained in:
parent
aaf4ec62cf
commit
d28127c807
2 changed files with 6 additions and 5 deletions
|
@ -53,9 +53,11 @@ Vector<AutoCompleteResponse> AutoComplete::get_suggestions(const String& code, c
|
||||||
return suggestions;
|
return suggestions;
|
||||||
}
|
}
|
||||||
|
|
||||||
String AutoComplete::text_of_token(const Vector<String>& lines, const Cpp::Token& token)
|
StringView 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);
|
ASSERT(token.m_start.line == token.m_end.line);
|
||||||
|
ASSERT(token.m_start.column <= token.m_end.column);
|
||||||
|
return lines[token.m_start.line].substring_view(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, const GUI::TextPosition& position)
|
Optional<size_t> AutoComplete::token_in_position(const Vector<Cpp::Token>& tokens, const GUI::TextPosition& position)
|
||||||
|
@ -83,8 +85,7 @@ Vector<AutoCompleteResponse> AutoComplete::identifier_prefixes(const Vector<Stri
|
||||||
if (token.m_type != Cpp::Token::Type::Identifier)
|
if (token.m_type != Cpp::Token::Type::Identifier)
|
||||||
continue;
|
continue;
|
||||||
auto text = text_of_token(lines, token);
|
auto text = text_of_token(lines, token);
|
||||||
if (text.starts_with(partial_input) && !suggestions_lookup.contains(text)) {
|
if (text.starts_with(partial_input) && suggestions_lookup.set(text) == AK::HashSetResult::InsertedNewEntry) {
|
||||||
suggestions_lookup.set(text);
|
|
||||||
suggestions.append({ text, partial_input.length(), HackStudio::CompletionKind::Identifier });
|
suggestions.append({ text, partial_input.length(), HackStudio::CompletionKind::Identifier });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static Optional<size_t> token_in_position(const Vector<Cpp::Token>&, const GUI::TextPosition&);
|
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 StringView 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 Vector<AutoCompleteResponse> identifier_prefixes(const Vector<String>& lines, const Vector<Cpp::Token>&, size_t target_token_index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue