From 01e515ed1d414b77480675e33b51b9e016502252 Mon Sep 17 00:00:00 2001 From: Radoslaw Zarzynski Date: Fri, 20 May 2016 14:48:41 +0200 Subject: [PATCH] rgw, optimization: avoid extra allocations in RGWHTTPHeadersCollector. Signed-off-by: Radoslaw Zarzynski --- src/rgw/rgw_http_client.cc | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/rgw/rgw_http_client.cc b/src/rgw/rgw_http_client.cc index 90217ad087b83..102ea60d32e75 100644 --- a/src/rgw/rgw_http_client.cc +++ b/src/rgw/rgw_http_client.cc @@ -1,6 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include + #include #include #include @@ -368,12 +370,12 @@ RGWHTTPClient::~RGWHTTPClient() int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len) { - const std::string header_line(static_cast(ptr), len); + const boost::string_ref header_line(static_cast(ptr), len); /* We're tokening the line that way due to backward compatibility. */ const size_t sep_loc = header_line.find_first_of(" \t:"); - if (std::string::npos == sep_loc) { + if (boost::string_ref::npos == sep_loc) { /* Wrongly formatted header? Just skip it. */ return 0; } @@ -384,16 +386,19 @@ int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len) return 0; } + const auto value_part = header_line.substr(sep_loc + 1); + /* Skip spaces and tabs after the separator. */ - const size_t val_loc_s = header_line.find_first_not_of(' ', sep_loc + 1); - const size_t val_loc_e = header_line.find_first_of("\r\n", sep_loc + 1); + const size_t val_loc_s = value_part.find_first_not_of(' '); + const size_t val_loc_e = value_part.find_first_of("\r\n"); - if (std::string::npos == val_loc_s || std::string::npos == val_loc_e) { + if (boost::string_ref::npos == val_loc_s || + boost::string_ref::npos == val_loc_e) { /* Empty value case. */ found_headers.emplace(name, header_value_t()); } else { found_headers.emplace(name, header_value_t( - header_line.substr(val_loc_s, val_loc_e - val_loc_s))); + value_part.substr(val_loc_s, val_loc_e - val_loc_s))); } return 0; -- 2.39.5