From b520a03c57a510b978ac5ee3382b446b72107669 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Tue, 25 Mar 2014 12:44:21 -0700 Subject: [PATCH] Prefer swap() member function to std::swap. We were hitting the inefficient generic std::swap for some derived types. --- builtin_set_color.cpp | 5 ++--- highlight.cpp | 2 +- parse_execution.cpp | 2 +- parse_tree.cpp | 4 ++-- 4 files changed, 6 insertions(+), 7 deletions(-) diff --git a/builtin_set_color.cpp b/builtin_set_color.cpp index 6e8f55b0a..0fdc1ac0b 100644 --- a/builtin_set_color.cpp +++ b/builtin_set_color.cpp @@ -235,9 +235,8 @@ static int builtin_set_color(parser_t &parser, wchar_t **argv) output_set_writer(saved_writer_func); /* Output the collected string */ - std::string local_output; - std::swap(builtin_set_color_output, local_output); - stdout_buffer.append(str2wcstring(local_output)); + stdout_buffer.append(str2wcstring(builtin_set_color_output)); + builtin_set_color_output.clear(); return STATUS_BUILTIN_OK; } diff --git a/highlight.cpp b/highlight.cpp index eaaec750a..87985ae6b 100644 --- a/highlight.cpp +++ b/highlight.cpp @@ -350,7 +350,7 @@ bool plain_statement_get_expanded_command(const wcstring &src, const parse_node_ if (expand_one(cmd, EXPAND_SKIP_CMDSUBST | EXPAND_SKIP_VARIABLES | EXPAND_SKIP_JOBS)) { /* Success, return the expanded string by reference */ - std::swap(cmd, *out_cmd); + out_cmd->swap(cmd); result = true; } } diff --git a/parse_execution.cpp b/parse_execution.cpp index 15c7de5f2..9267fb79b 100644 --- a/parse_execution.cpp +++ b/parse_execution.cpp @@ -1090,7 +1090,7 @@ bool parse_execution_context_t::determine_io_chain(const parse_node_t &statement if (out_chain && ! errored) { - std::swap(*out_chain, result); + out_chain->swap(result); } return ! errored; } diff --git a/parse_tree.cpp b/parse_tree.cpp index ae8e42d02..a1de4f966 100644 --- a/parse_tree.cpp +++ b/parse_tree.cpp @@ -687,13 +687,13 @@ void parse_ll_t::acquire_output(parse_node_tree_t *output, parse_error_list_t *e { if (output != NULL) { - std::swap(*output, this->nodes); + output->swap(this->nodes); } this->nodes.clear(); if (errors != NULL) { - std::swap(*errors, this->errors); + errors->swap(this->errors); } this->errors.clear(); this->symbol_stack.clear();