From b87a8400e373e85688ac3831ccfb09a10ba02038 Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 29 Oct 2024 18:21:07 +0900 Subject: [PATCH] Use pass-by-value for peeloff (#2578) This avoids copies when used with std::move. --- src/curl.cpp | 2 +- src/string_util.cpp | 6 ++++-- src/string_util.h | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/curl.cpp b/src/curl.cpp index 77656a4b54..f71a5b9541 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -4406,7 +4406,7 @@ bool S3fsCurl::CopyMultipartPostComplete() { std::string etag; partdata.uploaded = simple_parse_xml(bodydata.c_str(), bodydata.size(), "ETag", etag); - partdata.petag->etag = peeloff(etag); + partdata.petag->etag = peeloff(std::move(etag)); bodydata.clear(); headdata.clear(); diff --git a/src/string_util.cpp b/src/string_util.cpp index bdf786e3b1..6f3b628e4e 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -125,12 +125,14 @@ std::string trim(std::string s, const char *t /* = SPACES */) return trim_left(trim_right(std::move(s), t), t); } -std::string peeloff(const std::string& s) +std::string peeloff(std::string s) { if(s.size() < 2 || *s.cbegin() != '"' || *s.rbegin() != '"'){ return s; } - return s.substr(1, s.size() - 2); + s.erase(s.size() - 1); + s.erase(0, 1); + return s; } // diff --git a/src/string_util.h b/src/string_util.h index 4ccd3d4ff4..0b6b9caf83 100644 --- a/src/string_util.h +++ b/src/string_util.h @@ -80,7 +80,7 @@ std::string trim_left(std::string s, const char *t = SPACES); std::string trim_right(std::string s, const char *t = SPACES); std::string trim(std::string s, const char *t = SPACES); std::string lower(std::string s); -std::string peeloff(const std::string& s); +std::string peeloff(std::string s); // // Date string