mirror of
https://github.com/fish-shell/fish-shell
synced 2024-11-11 15:37:24 +00:00
Use std::move instead of swap in a few places where it improves clarity
This commit is contained in:
parent
fec83fa975
commit
1efb81456b
13 changed files with 26 additions and 28 deletions
|
@ -1330,7 +1330,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
|
|||
|
||||
// Return the string by reference, and then success.
|
||||
if (!errored) {
|
||||
output_str->swap(result);
|
||||
*output_str = std::move(result);
|
||||
}
|
||||
return !errored;
|
||||
}
|
||||
|
@ -1340,7 +1340,7 @@ bool unescape_string_in_place(wcstring *str, unescape_flags_t escape_special) {
|
|||
wcstring output;
|
||||
bool success = unescape_string_internal(str->c_str(), str->size(), &output, escape_special);
|
||||
if (success) {
|
||||
str->swap(output);
|
||||
*str = std::move(output);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
|
|
@ -598,15 +598,16 @@ class scoped_push {
|
|||
public:
|
||||
explicit scoped_push(T *r) : ref(r), saved_value(*r), restored(false) {}
|
||||
|
||||
scoped_push(T *r, const T &new_value) : ref(r), saved_value(*r), restored(false) {
|
||||
*r = new_value;
|
||||
scoped_push(T *r, T new_value) : ref(r), restored(false) {
|
||||
saved_value = std::move(*ref);
|
||||
*ref = std::move(new_value);
|
||||
}
|
||||
|
||||
~scoped_push() { restore(); }
|
||||
|
||||
void restore() {
|
||||
if (!restored) {
|
||||
std::swap(*ref, saved_value);
|
||||
*ref = std::move(saved_value);
|
||||
restored = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1624,7 +1624,7 @@ wcstring_list_t complete_get_wrap_chain(const wcstring &command) {
|
|||
wcstring target;
|
||||
while (!to_visit.empty()) {
|
||||
// Grab the next command to visit, put it in target.
|
||||
target.swap(to_visit.back());
|
||||
target = std::move(to_visit.back());
|
||||
to_visit.pop_back();
|
||||
|
||||
// Try inserting into visited. If it was already present, we skip it; this is how we avoid
|
||||
|
|
|
@ -389,13 +389,13 @@ void env_universal_t::acquire_variables(var_table_t *vars_to_acquire) {
|
|||
// source entry in vars since we are about to get rid of this->vars entirely.
|
||||
var_entry_t &src = src_iter->second;
|
||||
var_entry_t &dst = (*vars_to_acquire)[key];
|
||||
dst.val.swap(src.val);
|
||||
dst.val = std::move(src.val);
|
||||
dst.exportv = src.exportv;
|
||||
}
|
||||
}
|
||||
|
||||
// We have constructed all the callbacks and updated vars_to_acquire. Acquire it!
|
||||
this->vars.swap(*vars_to_acquire);
|
||||
this->vars = std::move(*vars_to_acquire);
|
||||
}
|
||||
|
||||
void env_universal_t::load_from_fd(int fd, callback_data_list_t *callbacks) {
|
||||
|
@ -844,7 +844,7 @@ void env_universal_t::parse_message_internal(const wcstring &msgstr, var_table_t
|
|||
if (unescape_string(tmp + 1, &val, 0)) {
|
||||
var_entry_t &entry = (*vars)[key];
|
||||
entry.exportv = exportv;
|
||||
entry.val.swap(val); // acquire the value
|
||||
entry.val = std::move(val); // acquire the value
|
||||
}
|
||||
} else {
|
||||
debug(1, PARSE_ERR, msg);
|
||||
|
|
|
@ -291,8 +291,8 @@ static bool io_transmogrify(const io_chain_t &in_chain, io_chain_t *out_chain,
|
|||
|
||||
// Now either return success, or clean up.
|
||||
if (success) {
|
||||
out_chain->swap(result_chain);
|
||||
out_opened_fds->swap(opened_fds);
|
||||
*out_chain = std::move(result_chain);
|
||||
*out_opened_fds = std::move(opened_fds);
|
||||
} else {
|
||||
result_chain.clear();
|
||||
io_cleanup_fds(opened_fds);
|
||||
|
|
|
@ -820,7 +820,7 @@ static int expand_variables(const wcstring &instr, std::vector<completion_t> *ou
|
|||
}
|
||||
|
||||
// string_values is the new var_item_list.
|
||||
var_item_list.swap(string_values);
|
||||
var_item_list = std::move(string_values);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -237,7 +237,7 @@ bool plain_statement_get_expanded_command(const wcstring &src, const parse_node_
|
|||
if (tree.command_for_plain_statement(plain_statement, src, &cmd) &&
|
||||
expand_one(cmd, EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES | EXPAND_SKIP_JOBS)) {
|
||||
// Success, return the expanded string by reference.
|
||||
out_cmd->swap(cmd);
|
||||
*out_cmd = std::move(cmd);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -293,7 +293,7 @@ static void iothread_service_main_thread_requests(void) {
|
|||
std::queue<main_thread_request_t *> request_queue;
|
||||
{
|
||||
scoped_lock queue_lock(s_main_thread_request_q_lock);
|
||||
std::swap(request_queue, s_main_thread_request_queue);
|
||||
request_queue.swap(s_main_thread_request_queue);
|
||||
}
|
||||
|
||||
if (!request_queue.empty()) {
|
||||
|
@ -326,7 +326,7 @@ static void iothread_service_result_queue() {
|
|||
std::queue<spawn_request_t> result_queue;
|
||||
{
|
||||
scoped_lock queue_lock(s_result_queue_lock);
|
||||
std::swap(result_queue, s_result_queue);
|
||||
result_queue.swap(s_result_queue);
|
||||
}
|
||||
|
||||
// Perform each completion in order. We are responsibile for cleaning them up.
|
||||
|
|
|
@ -948,14 +948,11 @@ parse_execution_result_t parse_execution_context_t::determine_arguments(
|
|||
}
|
||||
}
|
||||
|
||||
// Now copy over any expanded arguments. Do it using swap() to avoid extra allocations; this
|
||||
// Now copy over any expanded arguments. Use std::move() to avoid extra allocations; this
|
||||
// is called very frequently.
|
||||
size_t old_arg_count = out_arguments->size();
|
||||
size_t new_arg_count = arg_expanded.size();
|
||||
out_arguments->resize(old_arg_count + new_arg_count);
|
||||
for (size_t i = 0; i < new_arg_count; i++) {
|
||||
wcstring &new_arg = arg_expanded.at(i).completion;
|
||||
out_arguments->at(old_arg_count + i).swap(new_arg);
|
||||
out_arguments->reserve(out_arguments->size() + arg_expanded.size());
|
||||
for (completion_t &new_arg : arg_expanded) {
|
||||
out_arguments->push_back(std::move(new_arg.completion));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1035,7 +1032,7 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement
|
|||
}
|
||||
|
||||
if (out_chain && !errored) {
|
||||
out_chain->swap(result);
|
||||
*out_chain = std::move(result);
|
||||
}
|
||||
return !errored;
|
||||
}
|
||||
|
|
|
@ -1293,11 +1293,11 @@ parser_test_error_bits_t parse_util_detect_errors(const wcstring &buff_src,
|
|||
if (has_unclosed_block || has_unclosed_quote) res |= PARSER_TEST_INCOMPLETE;
|
||||
|
||||
if (out_errors != NULL) {
|
||||
out_errors->swap(parse_errors);
|
||||
*out_errors = std::move(parse_errors);
|
||||
}
|
||||
|
||||
if (out_tree != NULL) {
|
||||
out_tree->swap(node_tree);
|
||||
*out_tree = std::move(node_tree);
|
||||
}
|
||||
|
||||
return res;
|
||||
|
|
|
@ -72,7 +72,7 @@ static bool path_get_path_core(const wcstring &cmd, wcstring *out_path,
|
|||
continue;
|
||||
}
|
||||
if (S_ISREG(buff.st_mode)) {
|
||||
if (out_path) out_path->swap(nxt_path);
|
||||
if (out_path) *out_path = std::move(nxt_path);
|
||||
return true;
|
||||
}
|
||||
err = EACCES;
|
||||
|
|
|
@ -625,7 +625,7 @@ bool reader_data_t::expand_abbreviation_as_necessary(size_t cursor_backtrack) {
|
|||
// lengths.
|
||||
size_t new_buff_pos = el->position + new_cmdline.size() - el->text.size();
|
||||
|
||||
el->text.swap(new_cmdline);
|
||||
el->text = std::move(new_cmdline);
|
||||
update_buff_pos(el, new_buff_pos);
|
||||
data->command_line_changed(el);
|
||||
result = true;
|
||||
|
|
|
@ -609,7 +609,7 @@ wcstring tok_first(const wcstring &str) {
|
|||
tokenizer_t t(str.c_str(), TOK_SQUASH_ERRORS);
|
||||
tok_t token;
|
||||
if (t.next(&token) && token.type == TOK_STRING) {
|
||||
result.swap(token.text);
|
||||
result = std::move(token.text);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue