From 7a74198aa3cf88585eee879bd608df36fca12ced Mon Sep 17 00:00:00 2001 From: Aaron Gyes Date: Sat, 16 Mar 2019 19:32:07 -0700 Subject: [PATCH] parser: try to avoid some strings being copied --- src/parse_execution.cpp | 4 +--- src/parse_tree.cpp | 2 +- src/parse_tree.h | 2 +- src/parser.cpp | 2 +- src/parser.h | 2 +- 5 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/parse_execution.cpp b/src/parse_execution.cpp index 3d83c9035..c14aadd7f 100644 --- a/src/parse_execution.cpp +++ b/src/parse_execution.cpp @@ -734,8 +734,6 @@ parse_execution_result_t parse_execution_context_t::expand_command( // Get the unexpanded command string. We expect to always get it here. wcstring unexp_cmd = *command_for_plain_statement(statement, pstree->src); - wcstring cmd; - wcstring_list_t args; // Expand the string to produce completions, and report errors. expand_error_t expand_err = @@ -879,7 +877,7 @@ parse_execution_result_t parse_execution_context_t::populate_plain_process( proc->type = process_type; proc->set_argv(cmd_args); proc->set_io_chain(process_io_chain); - proc->actual_cmd = path_to_external_command; + proc->actual_cmd = std::move(path_to_external_command); return parse_execution_success; } diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index cd7b35568..d2e3774af 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -1135,7 +1135,7 @@ const parse_node_t *parse_node_tree_t::get_child(const parse_node_t &parent, nod return result; } -parsed_source_ref_t parse_source(wcstring src, parse_tree_flags_t flags, parse_error_list_t *errors, +parsed_source_ref_t parse_source(const wcstring &src, parse_tree_flags_t flags, parse_error_list_t *errors, parse_token_type_t goal) { parse_node_tree_t tree; if (!parse_tree_from_string(src, flags, &tree, errors, goal)) return {}; diff --git a/src/parse_tree.h b/src/parse_tree.h index 9e032f11d..8fc536131 100644 --- a/src/parse_tree.h +++ b/src/parse_tree.h @@ -233,7 +233,7 @@ struct parsed_source_t { }; /// Return a shared pointer to parsed_source_t, or null on failure. using parsed_source_ref_t = std::shared_ptr; -parsed_source_ref_t parse_source(wcstring src, parse_tree_flags_t flags, parse_error_list_t *errors, +parsed_source_ref_t parse_source(const wcstring &src, parse_tree_flags_t flags, parse_error_list_t *errors, parse_token_type_t goal = symbol_job_list); #endif diff --git a/src/parser.cpp b/src/parser.cpp index a8d30e0bf..572f9b5bb 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -629,7 +629,7 @@ profile_item_t *parser_t::create_profile_item() { return result; } -int parser_t::eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_type) { +int parser_t::eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type) { // Parse the source into a tree, if we can. parse_error_list_t error_list; parsed_source_ref_t ps = parse_source(cmd, parse_flag_none, &error_list); diff --git a/src/parser.h b/src/parser.h index ac251a4be..264b09cc8 100644 --- a/src/parser.h +++ b/src/parser.h @@ -222,7 +222,7 @@ class parser_t : public std::enable_shared_from_this { /// \param block_type The type of block to push on the block stack /// /// \return 0 on success, 1 on a parse error. - int eval(wcstring cmd, const io_chain_t &io, enum block_type_t block_type); + int eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type); /// Evaluate the parsed source ps. void eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type);