mirror of
https://github.com/mawww/kakoune.git
synced 2024-12-28 22:22:41 +03:00
Avoid copying token content strings in expand_token
We can move that data instead of copying
This commit is contained in:
parent
cac946b434
commit
cd67f2cf11
@ -323,9 +323,9 @@ Token parse_percent_token(Reader& reader, bool throw_on_unterminated)
|
||||
|
||||
template<bool single>
|
||||
std::conditional_t<single, String, Vector<String>>
|
||||
expand_token(const Token& token, const Context& context, const ShellContext& shell_context)
|
||||
expand_token(Token&& token, const Context& context, const ShellContext& shell_context)
|
||||
{
|
||||
auto& content = token.content;
|
||||
auto&& content = token.content;
|
||||
switch (token.type)
|
||||
{
|
||||
case Token::Type::ShellExpand:
|
||||
@ -386,7 +386,7 @@ expand_token(const Token& token, const Context& context, const ShellContext& she
|
||||
return {expand(content, context, shell_context)};
|
||||
case Token::Type::Raw:
|
||||
case Token::Type::RawQuoted:
|
||||
return {content};
|
||||
return {std::move(content)};
|
||||
default: kak_assert(false);
|
||||
}
|
||||
return {};
|
||||
@ -569,7 +569,7 @@ void CommandManager::execute(StringView command_line,
|
||||
shell_context.params.end());
|
||||
else
|
||||
{
|
||||
auto tokens = expand_token<false>(*token, context, shell_context);
|
||||
auto tokens = expand_token<false>(*std::move(token), context, shell_context);
|
||||
params.insert(params.end(),
|
||||
std::make_move_iterator(tokens.begin()),
|
||||
std::make_move_iterator(tokens.end()));
|
||||
|
@ -68,12 +68,20 @@ public:
|
||||
return m_value;
|
||||
}
|
||||
|
||||
T& operator*()
|
||||
T& operator*() &
|
||||
{
|
||||
kak_assert(m_valid);
|
||||
return m_value;
|
||||
}
|
||||
const T& operator*() const { return *const_cast<Optional&>(*this); }
|
||||
|
||||
T&& operator*() &&
|
||||
{
|
||||
kak_assert(m_valid);
|
||||
return std::move(m_value);
|
||||
}
|
||||
|
||||
const T& operator*() const & { return *const_cast<Optional&>(*this); }
|
||||
const T& operator*() const && { return *const_cast<Optional&>(*this); }
|
||||
|
||||
T* operator->()
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user