From 06cb0bbe9a927026b6f1f887ddbe761967ab9b3f Mon Sep 17 00:00:00 2001 From: Rosen Penev Date: Thu, 26 Dec 2019 21:54:21 -0800 Subject: [PATCH] [clang-tidy] Add several references Found with performance-unnecessary-value-param Signed-off-by: Rosen Penev --- src/complete.cpp | 6 +++--- src/env.cpp | 8 ++++---- src/env_universal_common.cpp | 2 +- src/env_universal_common.h | 2 +- src/exec.cpp | 10 +++++----- src/exec.h | 2 +- src/function.cpp | 3 ++- src/input.cpp | 5 +++-- src/input.h | 4 ++-- src/input_common.cpp | 4 ++-- src/input_common.h | 4 ++-- src/parser.cpp | 10 +++++----- src/parser.h | 4 ++-- src/proc.cpp | 2 +- src/proc.h | 2 +- 15 files changed, 35 insertions(+), 33 deletions(-) diff --git a/src/complete.cpp b/src/complete.cpp index b1214c2fe..a448366fd 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1643,16 +1643,16 @@ void complete(const wcstring &cmd_with_subcmds, std::vector *out_c /// Print the short switch \c opt, and the argument \c arg to the specified /// wcstring, but only if \c argument isn't an empty string. -static void append_switch(wcstring &out, wchar_t opt, const wcstring arg) { +static void append_switch(wcstring &out, wchar_t opt, const wcstring &arg) { if (arg.empty()) return; append_format(out, L" -%lc %ls", opt, escape_string(arg, ESCAPE_ALL).c_str()); } -static void append_switch(wcstring &out, const wcstring opt, const wcstring arg) { +static void append_switch(wcstring &out, const wcstring &opt, const wcstring &arg) { if (arg.empty()) return; append_format(out, L" --%ls %ls", opt.c_str(), escape_string(arg, ESCAPE_ALL).c_str()); } static void append_switch(wcstring &out, wchar_t opt) { append_format(out, L" -%lc", opt); } -static void append_switch(wcstring &out, const wcstring opt) { +static void append_switch(wcstring &out, const wcstring &opt) { append_format(out, L" --%ls", opt.c_str()); } diff --git a/src/env.cpp b/src/env.cpp index c44f574fa..7ed5426b2 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -878,7 +878,7 @@ class env_stack_impl_t final : public env_scoped_impl_t { /// Remove a variable from the chain \p node. /// \return true if the variable was found and removed. - bool remove_from_chain(env_node_ref_t node, const wcstring &key) const { + bool remove_from_chain(const env_node_ref_t &node, const wcstring &key) const { for (auto cursor = node; cursor; cursor = cursor->next) { auto iter = cursor->env.find(key); if (iter != cursor->env.end()) { @@ -901,7 +901,7 @@ class env_stack_impl_t final : public env_scoped_impl_t { void set_universal(const wcstring &key, wcstring_list_t val, const query_t &query); /// Set a variable in a given node \p node. - void set_in_node(env_node_ref_t node, const wcstring &key, wcstring_list_t &&val, + void set_in_node(const env_node_ref_t &node, const wcstring &key, wcstring_list_t &&val, const var_flags_t &flags); // Implement the default behavior of 'set' by finding the node for an unspecified scope. @@ -970,8 +970,8 @@ static wcstring_list_t colon_split(const wcstring_list_t &val) { return split_val; } -void env_stack_impl_t::set_in_node(env_node_ref_t node, const wcstring &key, wcstring_list_t &&val, - const var_flags_t &flags) { +void env_stack_impl_t::set_in_node(const env_node_ref_t &node, const wcstring &key, + wcstring_list_t &&val, const var_flags_t &flags) { env_var_t &var = node->env[key]; // Use an explicit exports, or inherit from the existing variable. diff --git a/src/env_universal_common.cpp b/src/env_universal_common.cpp index acb7bc783..8e71c301a 100644 --- a/src/env_universal_common.cpp +++ b/src/env_universal_common.cpp @@ -277,7 +277,7 @@ void env_universal_t::set_internal(const wcstring &key, const env_var_t &var) { } } -void env_universal_t::set(const wcstring &key, env_var_t var) { +void env_universal_t::set(const wcstring &key, const env_var_t &var) { scoped_lock locker(lock); this->set_internal(key, var); } diff --git a/src/env_universal_common.h b/src/env_universal_common.h index 12d12d3c2..ae4bd3691 100644 --- a/src/env_universal_common.h +++ b/src/env_universal_common.h @@ -103,7 +103,7 @@ class env_universal_t { maybe_t get_flags(const wcstring &name) const; // Sets a variable. - void set(const wcstring &key, env_var_t var); + void set(const wcstring &key, const env_var_t &var); // Removes a variable. Returns true if it was found, false if not. bool remove(const wcstring &key); diff --git a/src/exec.cpp b/src/exec.cpp index 02b510bad..32c7099e7 100644 --- a/src/exec.cpp +++ b/src/exec.cpp @@ -241,7 +241,7 @@ static void on_process_created(const std::shared_ptr &j, pid_t child_pid) /// (stdout), and there is a dup2 3->1, then we need to write to fd 3. Then exit the internal /// process. static bool run_internal_process(process_t *p, std::string outdata, std::string errdata, - io_chain_t ios) { + const io_chain_t &ios) { p->check_generations_before_launch(); // We want both the dup2s and the io_chain_ts to be kept alive by the background thread, because @@ -780,8 +780,8 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job /// \p conflicts contains the list of fds which pipes should avoid. /// \p allow_buffering if true, permit buffering the output. /// \return true on success, false on error. -static bool exec_block_or_func_process(parser_t &parser, std::shared_ptr j, process_t *p, - const fd_set_t &conflicts, io_chain_t io_chain, +static bool exec_block_or_func_process(parser_t &parser, const std::shared_ptr &j, + process_t *p, const fd_set_t &conflicts, io_chain_t io_chain, bool allow_buffering) { // Create an output buffer if we're piping to another process. shared_ptr block_output_bufferfill{}; @@ -839,7 +839,7 @@ static bool exec_block_or_func_process(parser_t &parser, std::shared_ptr /// \p deferred_pipes represents the pipes from our deferred process; if set ensure they get closed /// in any child. If \p is_deferred_run is true, then this is a deferred run; this affects how /// certain buffering works. \returns true on success, false on exec error. -static bool exec_process_in_job(parser_t &parser, process_t *p, std::shared_ptr j, +static bool exec_process_in_job(parser_t &parser, process_t *p, const std::shared_ptr &j, const io_chain_t &block_io, autoclose_pipes_t pipes, const fd_set_t &conflicts, const autoclose_pipes_t &deferred_pipes, size_t stdout_read_limit, bool is_deferred_run = false) { @@ -1027,7 +1027,7 @@ static bool should_claim_process_group_for_job(const shared_ptr &j) { DIE("unreachable"); } -bool exec_job(parser_t &parser, shared_ptr j, const job_lineage_t &lineage) { +bool exec_job(parser_t &parser, const shared_ptr &j, const job_lineage_t &lineage) { assert(j && "null job_t passed to exec_job!"); // Set to true if something goes wrong while executing the job, in which case the cleanup diff --git a/src/exec.h b/src/exec.h index 37fee0b25..af3f1481b 100644 --- a/src/exec.h +++ b/src/exec.h @@ -15,7 +15,7 @@ class job_t; struct job_lineage_t; class parser_t; -bool exec_job(parser_t &parser, std::shared_ptr j, const job_lineage_t &lineage); +bool exec_job(parser_t &parser, const std::shared_ptr &j, const job_lineage_t &lineage); /// Evaluate the expression cmd in a subshell, add the outputs into the list l. On return, the /// status flag as returned bu \c proc_gfet_last_status will not be changed. diff --git a/src/function.cpp b/src/function.cpp index f659239e0..283d79d89 100644 --- a/src/function.cpp +++ b/src/function.cpp @@ -166,7 +166,8 @@ void function_add(wcstring name, wcstring description, function_properties_ref_t // Create and store a new function. auto ins = funcset->funcs.emplace( - std::move(name), function_info_t(props, std::move(description), filename, is_autoload)); + std::move(name), + function_info_t(std::move(props), std::move(description), filename, is_autoload)); assert(ins.second && "Function should not already be present in the table"); (void)ins; } diff --git a/src/input.cpp b/src/input.cpp index 6aec246b3..e2600656d 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "common.h" @@ -427,9 +428,9 @@ bool inputter_t::mapping_is_match(const input_mapping_t &m) { return true; } -void inputter_t::queue_ch(char_event_t ch) { event_queue_.push_back(ch); } +void inputter_t::queue_ch(const char_event_t &ch) { event_queue_.push_back(std::move(ch)); } -void inputter_t::push_front(char_event_t ch) { event_queue_.push_front(ch); } +void inputter_t::push_front(const char_event_t &ch) { event_queue_.push_front(std::move(ch)); } /// \return the first mapping that matches, walking first over the user's mapping list, then the /// preset list. \return null if nothing matches. diff --git a/src/input.h b/src/input.h index 63e4e4533..45b714a12 100644 --- a/src/input.h +++ b/src/input.h @@ -57,10 +57,10 @@ class inputter_t { /// Enqueue a char event to the queue of unread characters that input_readch will return before /// actually reading from fd 0. - void queue_ch(char_event_t ch); + void queue_ch(const char_event_t &ch); /// Enqueue a char event to the front of the queue; this will be the next event returned. - void push_front(char_event_t ch); + void push_front(const char_event_t &ch); /// Sets the return status of the most recently executed input function. void function_set_status(bool status) { function_status_ = status; } diff --git a/src/input_common.cpp b/src/input_common.cpp index a333a5627..d877257bf 100644 --- a/src/input_common.cpp +++ b/src/input_common.cpp @@ -225,6 +225,6 @@ char_event_t input_event_queue_t::readch_timed(bool dequeue_timeouts) { return result; } -void input_event_queue_t::push_back(char_event_t ch) { queue_.push_back(ch); } +void input_event_queue_t::push_back(const char_event_t& ch) { queue_.push_back(ch); } -void input_event_queue_t::push_front(char_event_t ch) { queue_.push_front(ch); } +void input_event_queue_t::push_front(const char_event_t& ch) { queue_.push_front(ch); } diff --git a/src/input_common.h b/src/input_common.h index f9182fd33..2c5786717 100644 --- a/src/input_common.h +++ b/src/input_common.h @@ -186,11 +186,11 @@ class input_event_queue_t { /// Enqueue a character or a readline function to the queue of unread characters that /// readch will return before actually reading from fd 0. - void push_back(char_event_t ch); + void push_back(const char_event_t& ch); /// Add a character or a readline function to the front of the queue of unread characters. This /// will be the next character returned by readch. - void push_front(char_event_t ch); + void push_front(const char_event_t& ch); }; #endif diff --git a/src/parser.cpp b/src/parser.cpp index 0a6b7f4d5..e0ee0bb1b 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -626,7 +626,7 @@ eval_result_t parser_t::eval(const wcstring &cmd, const io_chain_t &io, } } -eval_result_t parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io, +eval_result_t parser_t::eval(const parsed_source_ref_t &ps, const io_chain_t &io, enum block_type_t block_type) { assert(block_type == block_type_t::top || block_type == block_type_t::subst); if (!ps->tree.empty()) { @@ -640,8 +640,8 @@ eval_result_t parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io, } template -eval_result_t parser_t::eval_node(parsed_source_ref_t ps, tnode_t node, job_lineage_t lineage, - block_type_t block_type) { +eval_result_t parser_t::eval_node(const parsed_source_ref_t &ps, tnode_t node, + job_lineage_t lineage, block_type_t block_type) { static_assert( std::is_same::value || std::is_same::value, "Unexpected node type"); @@ -683,9 +683,9 @@ eval_result_t parser_t::eval_node(parsed_source_ref_t ps, tnode_t node, job_l } // Explicit instantiations. TODO: use overloads instead? -template eval_result_t parser_t::eval_node(parsed_source_ref_t, tnode_t, +template eval_result_t parser_t::eval_node(const parsed_source_ref_t &, tnode_t, job_lineage_t, block_type_t); -template eval_result_t parser_t::eval_node(parsed_source_ref_t, tnode_t, +template eval_result_t parser_t::eval_node(const parsed_source_ref_t &, tnode_t, job_lineage_t, block_type_t); void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &errors, diff --git a/src/parser.h b/src/parser.h index 6357643bf..599f93299 100644 --- a/src/parser.h +++ b/src/parser.h @@ -268,13 +268,13 @@ class parser_t : public std::enable_shared_from_this { /// Evaluate the parsed source ps. /// Because the source has been parsed, a syntax error is impossible. - eval_result_t eval(parsed_source_ref_t ps, const io_chain_t &io, + eval_result_t eval(const parsed_source_ref_t &ps, const io_chain_t &io, block_type_t block_type = block_type_t::top); /// Evaluates a node. /// The node type must be grammar::statement or grammar::job_list. template - eval_result_t eval_node(parsed_source_ref_t ps, tnode_t node, job_lineage_t lineage, + eval_result_t eval_node(const parsed_source_ref_t &ps, tnode_t node, job_lineage_t lineage, block_type_t block_type = block_type_t::top); /// Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and diff --git a/src/proc.cpp b/src/proc.cpp index 0a418936a..60d779afb 100644 --- a/src/proc.cpp +++ b/src/proc.cpp @@ -269,7 +269,7 @@ void process_t::check_generations_before_launch() { gens_ = topic_monitor_t::principal().current_generations(); } -job_t::job_t(job_id_t job_id, const properties_t &props, job_lineage_t lineage) +job_t::job_t(job_id_t job_id, const properties_t &props, const job_lineage_t &lineage) : properties(props), job_id(job_id), root_constructed(lineage.root_constructed ? lineage.root_constructed : this->constructed) {} diff --git a/src/proc.h b/src/proc.h index 5042f35c7..63772b434 100644 --- a/src/proc.h +++ b/src/proc.h @@ -320,7 +320,7 @@ class job_t { void operator=(const job_t &) = delete; public: - job_t(job_id_t job_id, const properties_t &props, job_lineage_t lineage); + job_t(job_id_t job_id, const properties_t &props, const job_lineage_t &lineage); ~job_t(); /// Returns the command as a wchar_t *. */