]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rgw, optimization: avoid extra allocations in RGWHTTPHeadersCollector.
authorRadoslaw Zarzynski <rzarzynski@mirantis.com>
Fri, 20 May 2016 12:48:41 +0000 (14:48 +0200)
committerRadoslaw Zarzynski <rzarzynski@mirantis.com>
Thu, 2 Jun 2016 19:17:12 +0000 (21:17 +0200)
Signed-off-by: Radoslaw Zarzynski <rzarzynski@mirantis.com>
src/rgw/rgw_http_client.cc

index 90217ad087b832e7dafe2d5fb855dd830d654500..102ea60d32e752938315995343dda2554a89c1d0 100644 (file)
@@ -1,6 +1,8 @@
 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
 // vim: ts=8 sw=2 smarttab
 
+#include <boost/utility/string_ref.hpp>
+
 #include <curl/curl.h>
 #include <curl/easy.h>
 #include <curl/multi.h>
@@ -368,12 +370,12 @@ RGWHTTPClient::~RGWHTTPClient()
 
 int RGWHTTPHeadersCollector::receive_header(void * const ptr, const size_t len)
 {
-  const std::string header_line(static_cast<const char * const>(ptr), len);
+  const boost::string_ref header_line(static_cast<const char * const>(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;