summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMaxime Coste <mawww@kakoune.org>2017-10-17 10:25:20 +0800
committerMaxime Coste <mawww@kakoune.org>2017-10-17 10:25:20 +0800
commitddc307b8e9863a110d4a4ee142f8a873d4996e38 (patch)
treeae8b86c9d3fc71dce7b2b9ff58edbb449c0c1f55 /src
parent145cf843dd07d579a0e4834665446eba17c96cb5 (diff)
Optimize CommandManager::execute handling of tokens
Instead of walking a list of tokens and inserting eventual new ones in the middle, use a stack of token and push new ones on top.
Diffstat (limited to 'src')
-rw-r--r--src/command_manager.cc27
1 files changed, 14 insertions, 13 deletions
diff --git a/src/command_manager.cc b/src/command_manager.cc
index e6875ed4..2a1e865f 100644
--- a/src/command_manager.cc
+++ b/src/command_manager.cc
@@ -473,36 +473,37 @@ void CommandManager::execute(StringView command_line,
TokenList tokens = parse<true>(command_line);
if (tokens.empty())
return;
+ // Tokens are going to be read as a stack
+ std::reverse(tokens.begin(), tokens.end());
DisplayCoord command_coord;
Vector<String> params;
- for (auto it = tokens.begin(); it != tokens.end(); )
+ while (not tokens.empty())
{
+ Token token = std::move(tokens.back());
+ tokens.pop_back();
if (params.empty())
- command_coord = it->coord;
+ command_coord = token.coord;
- if (it->type == Token::Type::CommandSeparator)
+ if (token.type == Token::Type::CommandSeparator)
{
execute_single_command(params, context, shell_context, command_coord);
params.clear();
}
// Shell expand are retokenized
- else if (it->type == Token::Type::ShellExpand)
+ else if (token.type == Token::Type::ShellExpand)
{
- auto new_tokens = parse<true>(expand_token(*it, context,
+ auto new_tokens = parse<true>(expand_token(token, context,
shell_context));
- it = tokens.insert(tokens.erase(it),
- std::make_move_iterator(new_tokens.begin()),
- std::make_move_iterator(new_tokens.end()));
- continue; // skip incrementing, we already point to next token
+ tokens.insert(tokens.end(),
+ std::make_move_iterator(new_tokens.rbegin()),
+ std::make_move_iterator(new_tokens.rend()));
}
- else if (it->type == Token::Type::ArgExpand and it->content == '@')
+ else if (token.type == Token::Type::ArgExpand and token.content == '@')
params.insert(params.end(), shell_context.params.begin(),
shell_context.params.end());
else
- params.push_back(expand_token(*it, context, shell_context));
-
- ++it;
+ params.push_back(expand_token(token, context, shell_context));
}
execute_single_command(params, context, shell_context, command_coord);
}