mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-10 23:24:39 +00:00
Constructors to accept more parameters by value
In cases where the constructor needs to take ownership of parameters, pass them by value and use std::move.
This commit is contained in:
parent
74e6a82849
commit
da84b38430
19 changed files with 53 additions and 47 deletions
|
@ -306,9 +306,9 @@ class ParserError {
|
|||
ParserError();
|
||||
explicit ParserError(EErrorCodes a_iErrc);
|
||||
explicit ParserError(const string_type &sMsg);
|
||||
ParserError(EErrorCodes a_iErrc, const string_type &sTok, int a_iPos = -1);
|
||||
ParserError(EErrorCodes a_iErrc, int a_iPos, const string_type &sTok);
|
||||
ParserError(const char_type *a_szMsg, int a_iPos = -1, const string_type &sTok = string_type());
|
||||
ParserError(EErrorCodes a_iErrc, string_type sTok, int a_iPos = -1);
|
||||
ParserError(EErrorCodes a_iErrc, int a_iPos, string_type sTok);
|
||||
ParserError(const char_type *a_szMsg, int a_iPos = -1, string_type sTok = string_type());
|
||||
ParserError(ParserError &&) = default;
|
||||
ParserError &operator=(ParserError &&) = default;
|
||||
ParserError(const ParserError &a_Obj) = default;
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace mu {
|
||||
//---------------------------------------------------------------------------
|
||||
string_type parser_error_for_code(EErrorCodes code) {
|
||||
|
@ -144,8 +146,8 @@ ParserError::ParserError(const string_type &sMsg) {
|
|||
\param [in] sTok The token string related to this error.
|
||||
\param [in] a_iPos the position in the expression where the error occurred.
|
||||
*/
|
||||
ParserError::ParserError(EErrorCodes iErrc, const string_type &sTok, int iPos)
|
||||
: m_strTok(sTok), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
ParserError::ParserError(EErrorCodes iErrc, string_type sTok, int iPos)
|
||||
: m_strTok(std::move(sTok)), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
m_strMsg = parser_error_for_code(m_iErrc);
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
|
@ -159,8 +161,8 @@ ParserError::ParserError(EErrorCodes iErrc, const string_type &sTok, int iPos)
|
|||
\param [in] iPos the position in the expression where the error occurred.
|
||||
\param [in] sTok The token string related to this error.
|
||||
*/
|
||||
ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok)
|
||||
: m_strMsg(), m_strTok(sTok), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
ParserError::ParserError(EErrorCodes iErrc, int iPos, string_type sTok)
|
||||
: m_strMsg(), m_strTok(std::move(sTok)), m_iPos(iPos), m_iErrc(iErrc) {
|
||||
m_strMsg = parser_error_for_code(m_iErrc);
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
|
@ -174,8 +176,8 @@ ParserError::ParserError(EErrorCodes iErrc, int iPos, const string_type &sTok)
|
|||
\param [in] iPos the position related to the error.
|
||||
\param [in] sTok The token string related to this error.
|
||||
*/
|
||||
ParserError::ParserError(const char_type *szMsg, int iPos, const string_type &sTok)
|
||||
: m_strMsg(szMsg), m_strTok(sTok), m_iPos(iPos), m_iErrc(ecGENERIC) {
|
||||
ParserError::ParserError(const char_type *szMsg, int iPos, string_type sTok)
|
||||
: m_strMsg(szMsg), m_strTok(std::move(sTok)), m_iPos(iPos), m_iErrc(ecGENERIC) {
|
||||
stringstream_type stream;
|
||||
stream << (int)m_iPos;
|
||||
ReplaceSubString(m_strMsg, _T("$POS$"), stream.str());
|
||||
|
|
|
@ -46,9 +46,9 @@ file_access_attempt_t access_file(const wcstring &path, int mode) {
|
|||
return result;
|
||||
}
|
||||
|
||||
autoload_t::autoload_t(const wcstring &env_var_name_var,
|
||||
autoload_t::autoload_t(wcstring env_var_name_var,
|
||||
command_removed_function_t cmd_removed_callback)
|
||||
: env_var_name(env_var_name_var), command_removed(cmd_removed_callback) {}
|
||||
: env_var_name(std::move(env_var_name_var)), command_removed(cmd_removed_callback) {}
|
||||
|
||||
void autoload_t::entry_was_evicted(wcstring key, autoload_function_t node) {
|
||||
// This should only ever happen on the main thread.
|
||||
|
|
|
@ -71,7 +71,7 @@ class autoload_t : public lru_cache_t<autoload_t, autoload_function_t> {
|
|||
void entry_was_evicted(wcstring key, autoload_function_t node);
|
||||
|
||||
// Create an autoload_t for the given environment variable name.
|
||||
autoload_t(const wcstring &env_var_name_var, command_removed_function_t callback);
|
||||
autoload_t(wcstring env_var_name_var, command_removed_function_t callback);
|
||||
|
||||
/// Autoload the specified file, if it exists in the specified path. Do not load it multiple
|
||||
/// times unless its timestamp changes or parse_util_unload is called.
|
||||
|
|
|
@ -682,8 +682,8 @@ class string_matcher_t {
|
|||
int total_matched;
|
||||
|
||||
public:
|
||||
string_matcher_t(const options_t &opts_, io_streams_t &streams_)
|
||||
: opts(opts_), streams(streams_), total_matched(0) {}
|
||||
string_matcher_t(options_t opts_, io_streams_t &streams_)
|
||||
: opts(std::move(opts_)), streams(streams_), total_matched(0) {}
|
||||
|
||||
virtual ~string_matcher_t() {}
|
||||
virtual bool report_matches(const wchar_t *arg) = 0;
|
||||
|
@ -956,8 +956,8 @@ class string_replacer_t {
|
|||
io_streams_t &streams;
|
||||
|
||||
public:
|
||||
string_replacer_t(const wchar_t *argv0_, const options_t &opts_, io_streams_t &streams_)
|
||||
: argv0(argv0_), opts(opts_), total_replaced(0), streams(streams_) {}
|
||||
string_replacer_t(const wchar_t *argv0_, options_t opts_, io_streams_t &streams_)
|
||||
: argv0(argv0_), opts(std::move(opts_)), total_replaced(0), streams(streams_) {}
|
||||
|
||||
virtual ~string_replacer_t() {}
|
||||
int replace_count() { return total_replaced; }
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "builtin.h"
|
||||
#include "common.h"
|
||||
|
@ -155,7 +156,7 @@ class test_parser {
|
|||
const wcstring &arg(unsigned int idx) { return strings.at(idx); }
|
||||
|
||||
public:
|
||||
explicit test_parser(const wcstring_list_t &val) : strings(val) {}
|
||||
explicit test_parser(wcstring_list_t val) : strings(std::move(val)) {}
|
||||
|
||||
unique_ptr<expression> parse_expression(unsigned int start, unsigned int end);
|
||||
unique_ptr<expression> parse_3_arg_expression(unsigned int start, unsigned int end);
|
||||
|
@ -183,7 +184,7 @@ struct range_t {
|
|||
/// Base class for expressions.
|
||||
class expression {
|
||||
protected:
|
||||
expression(token_t what, range_t where) : token(what), range(where) {}
|
||||
expression(token_t what, range_t where) : token(what), range(std::move(where)) {}
|
||||
|
||||
public:
|
||||
const token_t token;
|
||||
|
@ -199,8 +200,8 @@ class expression {
|
|||
class unary_primary : public expression {
|
||||
public:
|
||||
wcstring arg;
|
||||
unary_primary(token_t tok, range_t where, const wcstring &what)
|
||||
: expression(tok, where), arg(what) {}
|
||||
unary_primary(token_t tok, range_t where, wcstring what)
|
||||
: expression(tok, where), arg(std::move(what)) {}
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
|
@ -210,8 +211,8 @@ class binary_primary : public expression {
|
|||
wcstring arg_left;
|
||||
wcstring arg_right;
|
||||
|
||||
binary_primary(token_t tok, range_t where, const wcstring &left, const wcstring &right)
|
||||
: expression(tok, where), arg_left(left), arg_right(right) {}
|
||||
binary_primary(token_t tok, range_t where, wcstring left, wcstring right)
|
||||
: expression(tok, where), arg_left(std::move(left)), arg_right(std::move(right)) {}
|
||||
bool evaluate(wcstring_list_t &errors);
|
||||
};
|
||||
|
||||
|
|
|
@ -153,8 +153,8 @@ class completion_entry_t {
|
|||
void add_option(const complete_entry_opt_t &opt);
|
||||
bool remove_option(const wcstring &option, complete_option_type_t type);
|
||||
|
||||
completion_entry_t(const wcstring &c, bool type)
|
||||
: cmd(c), cmd_is_path(type), order(++kCompleteOrder) {}
|
||||
completion_entry_t(wcstring c, bool type)
|
||||
: cmd(std::move(c)), cmd_is_path(type), order(++kCompleteOrder) {}
|
||||
};
|
||||
|
||||
/// Set of all completion entries.
|
||||
|
@ -212,7 +212,7 @@ completion_t::completion_t(wcstring comp, wcstring desc, string_fuzzy_match_t ma
|
|||
complete_flags_t flags_val)
|
||||
: completion(std::move(comp)),
|
||||
description(std::move(desc)),
|
||||
match(mat),
|
||||
match(std::move(mat)),
|
||||
flags(resolve_auto_space(completion, flags_val)) {}
|
||||
|
||||
completion_t::completion_t(const completion_t &him) = default;
|
||||
|
@ -310,7 +310,7 @@ class completer_t {
|
|||
}
|
||||
|
||||
public:
|
||||
completer_t(const wcstring &c, completion_request_flags_t f) : flags(f), initial_cmd(c) {}
|
||||
completer_t(wcstring c, completion_request_flags_t f) : flags(f), initial_cmd(std::move(c)) {}
|
||||
|
||||
bool empty() const { return completions.empty(); }
|
||||
const std::vector<completion_t> &get_completions() { return completions; }
|
||||
|
|
|
@ -255,8 +255,8 @@ static bool append_file_entry(fish_message_type_t type, const wcstring &key_in,
|
|||
return success;
|
||||
}
|
||||
|
||||
env_universal_t::env_universal_t(const wcstring &path)
|
||||
: explicit_vars_path(path), tried_renaming(false), last_read_file(kInvalidFileID) {}
|
||||
env_universal_t::env_universal_t(wcstring path)
|
||||
: explicit_vars_path(std::move(path)), tried_renaming(false), last_read_file(kInvalidFileID) {}
|
||||
|
||||
maybe_t<env_var_t> env_universal_t::get(const wcstring &name) const {
|
||||
var_table_t::const_iterator where = vars.find(name);
|
||||
|
|
|
@ -22,8 +22,8 @@ struct callback_data_t {
|
|||
wcstring key;
|
||||
wcstring val;
|
||||
|
||||
callback_data_t(fish_message_type_t t, const wcstring &k, const wcstring &v)
|
||||
: type(t), key(k), val(v) {}
|
||||
callback_data_t(fish_message_type_t t, wcstring k, wcstring v)
|
||||
: type(t), key(std::move(k)), val(std::move(v)) {}
|
||||
};
|
||||
|
||||
typedef std::vector<struct callback_data_t> callback_data_list_t;
|
||||
|
@ -68,7 +68,7 @@ class env_universal_t {
|
|||
static var_table_t read_message_internal(int fd);
|
||||
|
||||
public:
|
||||
explicit env_universal_t(const wcstring &path);
|
||||
explicit env_universal_t(wcstring path);
|
||||
|
||||
// Get the value of the variable with the specified name.
|
||||
maybe_t<env_var_t> get(const wcstring &name) const;
|
||||
|
|
|
@ -687,12 +687,12 @@ class highlighter_t {
|
|||
public:
|
||||
// Constructor
|
||||
highlighter_t(const wcstring &str, size_t pos, const env_vars_snapshot_t &ev,
|
||||
const wcstring &wd, bool can_do_io)
|
||||
wcstring wd, bool can_do_io)
|
||||
: buff(str),
|
||||
cursor_pos(pos),
|
||||
vars(ev),
|
||||
io_ok(can_do_io),
|
||||
working_directory(wd),
|
||||
working_directory(std::move(wd)),
|
||||
color_array(str.size()) {
|
||||
// Parse the tree.
|
||||
parse_tree_from_string(buff, parse_flag_continue_after_error | parse_flag_include_comments,
|
||||
|
|
|
@ -721,8 +721,8 @@ history_t &history_t::history_with_name(const wcstring &name) {
|
|||
return histories.get_creating(name);
|
||||
}
|
||||
|
||||
history_t::history_t(const wcstring &pname)
|
||||
: name(pname),
|
||||
history_t::history_t(wcstring pname)
|
||||
: name(std::move(pname)),
|
||||
first_unwritten_new_item_index(0),
|
||||
has_pending_item(false),
|
||||
disable_automatic_save_counter(0),
|
||||
|
|
|
@ -216,7 +216,7 @@ class history_t {
|
|||
history_item_t item_at_index_assume_locked(size_t idx);
|
||||
|
||||
public:
|
||||
explicit history_t(const wcstring &); // constructor
|
||||
explicit history_t(wcstring ); // constructor
|
||||
|
||||
// Returns history with the given name, creating it if necessary.
|
||||
static history_t &history_with_name(const wcstring &name);
|
||||
|
|
|
@ -45,9 +45,9 @@ struct input_mapping_t {
|
|||
/// New mode that should be switched to after command evaluation.
|
||||
wcstring sets_mode;
|
||||
|
||||
input_mapping_t(const wcstring &s, const std::vector<wcstring> &c, const wcstring &m,
|
||||
const wcstring &sm)
|
||||
: seq(s), commands(c), mode(m), sets_mode(sm) {
|
||||
input_mapping_t(wcstring s, std::vector<wcstring> c, wcstring m,
|
||||
wcstring sm)
|
||||
: seq(std::move(s)), commands(std::move(c)), mode(std::move(m)), sets_mode(std::move(sm)) {
|
||||
static unsigned int s_last_input_map_spec_order = 0;
|
||||
specification_order = ++s_last_input_map_spec_order;
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <list>
|
||||
#include <memory>
|
||||
#include <type_traits>
|
||||
#include <utility>
|
||||
|
||||
#include "common.h"
|
||||
#include "env.h"
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <algorithm>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
#include "common.h"
|
||||
#include "env.h"
|
||||
|
@ -857,8 +858,8 @@ if_block_t::if_block_t() : block_t(IF) {}
|
|||
|
||||
event_block_t::event_block_t(const event_t &evt) : block_t(EVENT), event(evt) {}
|
||||
|
||||
function_block_t::function_block_t(const process_t *p, const wcstring &n, bool shadows)
|
||||
: block_t(shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW), process(p), name(n) {}
|
||||
function_block_t::function_block_t(const process_t *p, wcstring n, bool shadows)
|
||||
: block_t(shadows ? FUNCTION_CALL : FUNCTION_CALL_NO_SHADOW), process(p), name(std::move(n)) {}
|
||||
|
||||
source_block_t::source_block_t(const wchar_t *src) : block_t(SOURCE), source_file(src) {}
|
||||
|
||||
|
|
|
@ -111,7 +111,7 @@ struct event_block_t : public block_t {
|
|||
struct function_block_t : public block_t {
|
||||
const process_t *process;
|
||||
wcstring name;
|
||||
function_block_t(const process_t *p, const wcstring &n, bool shadows);
|
||||
function_block_t(const process_t *p, wcstring n, bool shadows);
|
||||
};
|
||||
|
||||
struct source_block_t : public block_t {
|
||||
|
|
|
@ -32,6 +32,7 @@
|
|||
|
||||
#include <algorithm> // IWYU pragma: keep
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#include "common.h"
|
||||
|
@ -351,8 +352,8 @@ process_t::process_t() {}
|
|||
/// the Linux kernel will use it for kernel processes.
|
||||
/// -1 should not be used; it is a possible return value of the getpgid()
|
||||
/// function
|
||||
job_t::job_t(job_id_t jobid, const io_chain_t &bio)
|
||||
: block_io(bio), pgid(-2), tmodes(), job_id(jobid), flags(0) {}
|
||||
job_t::job_t(job_id_t jobid, io_chain_t bio)
|
||||
: block_io(std::move(bio)), pgid(-2), tmodes(), job_id(jobid), flags(0) {}
|
||||
|
||||
job_t::~job_t() { release_job_id(job_id); }
|
||||
|
||||
|
|
|
@ -177,7 +177,7 @@ class job_t {
|
|||
void operator=(const job_t &) = delete;
|
||||
|
||||
public:
|
||||
job_t(job_id_t jobid, const io_chain_t &bio);
|
||||
job_t(job_id_t jobid, io_chain_t bio);
|
||||
~job_t();
|
||||
|
||||
/// Returns whether the command is empty.
|
||||
|
|
|
@ -611,8 +611,8 @@ class wildcard_expander_t {
|
|||
}
|
||||
|
||||
public:
|
||||
wildcard_expander_t(const wcstring &wd, expand_flags_t f, std::vector<completion_t> *r)
|
||||
: working_directory(wd),
|
||||
wildcard_expander_t(wcstring wd, expand_flags_t f, std::vector<completion_t> *r)
|
||||
: working_directory(std::move(wd)),
|
||||
flags(f),
|
||||
resolved_completions(r),
|
||||
did_interrupt(false),
|
||||
|
|
Loading…
Reference in a new issue