From 825c1bac6b61ce3f79f291d3a3f34bad80e75039 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 24 Sep 2013 23:53:55 +0900 Subject: [PATCH] shrpx_downstream.cc: Utilize std::move --- src/shrpx_downstream.cc | 36 +++++++++++++++++------------------- src/shrpx_downstream.h | 12 ++++++------ src/shrpx_http2_upstream.cc | 2 +- src/shrpx_spdy_upstream.cc | 2 +- 4 files changed, 25 insertions(+), 27 deletions(-) diff --git a/src/shrpx_downstream.cc b/src/shrpx_downstream.cc index c693262c..08f4239c 100644 --- a/src/shrpx_downstream.cc +++ b/src/shrpx_downstream.cc @@ -190,18 +190,17 @@ Headers::const_iterator Downstream::get_norm_request_header return get_norm_header(request_headers_, name); } -void Downstream::add_request_header(const std::string& name, - const std::string& value) +void Downstream::add_request_header(std::string name, std::string value) { request_header_key_prev_ = true; - request_headers_.push_back(std::make_pair(name, value)); + request_headers_.emplace_back(std::move(name), std::move(value)); } -void Downstream::set_last_request_header_value(const std::string& value) +void Downstream::set_last_request_header_value(std::string value) { request_header_key_prev_ = false; Headers::value_type &item = request_headers_.back(); - item.second = value; + item.second = std::move(value); check_transfer_encoding_chunked(&chunked_request_, item); check_expect_100_continue(&request_expect_100_continue_, item); } @@ -214,20 +213,20 @@ bool Downstream::get_request_header_key_prev() const void Downstream::append_last_request_header_key(const char *data, size_t len) { assert(request_header_key_prev_); - Headers::value_type &item = request_headers_.back(); + auto& item = request_headers_.back(); item.first.append(data, len); } void Downstream::append_last_request_header_value(const char *data, size_t len) { assert(!request_header_key_prev_); - Headers::value_type &item = request_headers_.back(); + auto& item = request_headers_.back(); item.second.append(data, len); } -void Downstream::set_request_method(const std::string& method) +void Downstream::set_request_method(std::string method) { - request_method_ = method; + request_method_ = std::move(method); } const std::string& Downstream::get_request_method() const @@ -235,9 +234,9 @@ const std::string& Downstream::get_request_method() const return request_method_; } -void Downstream::set_request_path(const std::string& path) +void Downstream::set_request_path(std::string path) { - request_path_ = path; + request_path_ = std::move(path); } void Downstream::append_request_path(const char *data, size_t len) @@ -372,20 +371,19 @@ Headers::const_iterator Downstream::get_norm_response_header return get_norm_header(response_headers_, name); } -void Downstream::add_response_header(const std::string& name, - const std::string& value) +void Downstream::add_response_header(std::string name, std::string value) { response_header_key_prev_ = true; - response_headers_.push_back(std::make_pair(name, value)); + response_headers_.emplace_back(std::move(name), std::move(value)); check_transfer_encoding_chunked(&chunked_response_, response_headers_.back()); } -void Downstream::set_last_response_header_value(const std::string& value) +void Downstream::set_last_response_header_value(std::string value) { response_header_key_prev_ = false; - Headers::value_type &item = response_headers_.back(); - item.second = value; + auto& item = response_headers_.back(); + item.second = std::move(value); check_transfer_encoding_chunked(&chunked_response_, item); } @@ -397,7 +395,7 @@ bool Downstream::get_response_header_key_prev() const void Downstream::append_last_response_header_key(const char *data, size_t len) { assert(response_header_key_prev_); - Headers::value_type &item = response_headers_.back(); + auto& item = response_headers_.back(); item.first.append(data, len); } @@ -405,7 +403,7 @@ void Downstream::append_last_response_header_value(const char *data, size_t len) { assert(!response_header_key_prev_); - Headers::value_type &item = response_headers_.back(); + auto& item = response_headers_.back(); item.second.append(data, len); } diff --git a/src/shrpx_downstream.h b/src/shrpx_downstream.h index add47649..f3662d30 100644 --- a/src/shrpx_downstream.h +++ b/src/shrpx_downstream.h @@ -93,16 +93,16 @@ public: // called after calling normalize_request_headers(). Headers::const_iterator get_norm_request_header (const std::string& name) const; - void add_request_header(const std::string& name, const std::string& value); - void set_last_request_header_value(const std::string& value); + void add_request_header(std::string name, std::string value); + void set_last_request_header_value(std::string value); bool get_request_header_key_prev() const; void append_last_request_header_key(const char *data, size_t len); void append_last_request_header_value(const char *data, size_t len); - void set_request_method(const std::string& method); + void set_request_method(std::string method); const std::string& get_request_method() const; - void set_request_path(const std::string& path); + void set_request_path(std::string path); void append_request_path(const char *data, size_t len); const std::string& get_request_path() const; void set_request_major(int major); @@ -138,8 +138,8 @@ public: // called after calling normalize_response_headers(). Headers::const_iterator get_norm_response_header (const std::string& name) const; - void add_response_header(const std::string& name, const std::string& value); - void set_last_response_header_value(const std::string& value); + void add_response_header(std::string name, std::string value); + void set_last_response_header_value(std::string value); bool get_response_header_key_prev() const; void append_last_response_header_key(const char *data, size_t len); diff --git a/src/shrpx_http2_upstream.cc b/src/shrpx_http2_upstream.cc index 3026f135..26139e20 100644 --- a/src/shrpx_http2_upstream.cc +++ b/src/shrpx_http2_upstream.cc @@ -261,7 +261,7 @@ int on_frame_recv_callback reqpath += "://"; reqpath += http2::value_to_str(host); reqpath += http2::value_to_str(path); - downstream->set_request_path(reqpath); + downstream->set_request_path(std::move(reqpath)); } else { downstream->set_request_path(http2::value_to_str(path)); } diff --git a/src/shrpx_spdy_upstream.cc b/src/shrpx_spdy_upstream.cc index 03189948..2b14967e 100644 --- a/src/shrpx_spdy_upstream.cc +++ b/src/shrpx_spdy_upstream.cc @@ -204,7 +204,7 @@ void on_ctrl_recv_callback reqpath += "://"; reqpath += host; reqpath += path; - downstream->set_request_path(reqpath); + downstream->set_request_path(std::move(reqpath)); } else { downstream->set_request_path(path); }