Skip to content

Commit

Permalink
Use pass-by-value for peeloff (s3fs-fuse#2578)
Browse files Browse the repository at this point in the history
This avoids copies when used with std::move.
  • Loading branch information
gaul authored Oct 29, 2024
1 parent 3b226ed commit b87a840
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/curl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
6 changes: 4 additions & 2 deletions src/string_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

//
Expand Down
2 changes: 1 addition & 1 deletion src/string_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b87a840

Please sign in to comment.