diff --git a/src/command_manager.cc b/src/command_manager.cc index 6191a1e6..113b4298 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -323,9 +323,9 @@ Token parse_percent_token(Reader& reader, bool throw_on_unterminated) template std::conditional_t> -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(*token, context, shell_context); + auto tokens = expand_token(*std::move(token), context, shell_context); params.insert(params.end(), std::make_move_iterator(tokens.begin()), std::make_move_iterator(tokens.end())); diff --git a/src/optional.hh b/src/optional.hh index 8531042e..e9386fa8 100644 --- a/src/optional.hh +++ b/src/optional.hh @@ -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(*this); } + + T&& operator*() && + { + kak_assert(m_valid); + return std::move(m_value); + } + + const T& operator*() const & { return *const_cast(*this); } + const T& operator*() const && { return *const_cast(*this); } T* operator->() {