From 07636c8a8d18cb491e411e89bf3b9f091353001c Mon Sep 17 00:00:00 2001 From: Andrew Gaul Date: Tue, 29 Jan 2019 10:44:33 -0800 Subject: [PATCH] Prefer specific [io]stringstream where possible These better communicate intent and are slightly more efficient. --- src/addhead.cpp | 12 ++++++------ src/curl.cpp | 8 ++++---- src/fdcache.cpp | 10 +++++----- src/s3fs_util.cpp | 14 +++++++------- src/string_util.cpp | 2 +- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/src/addhead.cpp b/src/addhead.cpp index 1df3533..ba09b3a 100644 --- a/src/addhead.cpp +++ b/src/addhead.cpp @@ -93,10 +93,10 @@ bool AdditionalHeader::Load(const char* file) continue; } // load a line - stringstream ss(line); - string key; // suffix(key) - string head; // additional HTTP header - string value; // header value + istringstream ss(line); + string key; // suffix(key) + string head; // additional HTTP header + string value; // header value if(0 == isblank(line[0])){ ss >> key; } @@ -245,8 +245,8 @@ bool AdditionalHeader::Dump(void) const return true; } - stringstream ssdbg; - int cnt = 1; + ostringstream ssdbg; + int cnt = 1; ssdbg << "Additional Header list[" << addheadlist.size() << "] = {" << endl; diff --git a/src/curl.cpp b/src/curl.cpp index c7a4788..ef0d94c 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -611,7 +611,7 @@ bool S3fsCurl::InitMimeType(const char* MimeFile) continue; } - stringstream tmp(line); + istringstream tmp(line); string mimeType; tmp >> mimeType; while(tmp){ @@ -808,7 +808,7 @@ size_t S3fsCurl::HeaderCallback(void* data, size_t blockSize, size_t numBlocks, headers_t* headers = reinterpret_cast(userPtr); string header(reinterpret_cast(data), blockSize * numBlocks); string key; - stringstream ss(header); + istringstream ss(header); if(getline(ss, key, ':')){ // Force to lower, only "x-amz" @@ -3681,7 +3681,7 @@ int S3fsCurl::MultipartHeadRequest(const char* tpath, off_t size, headers_t& met off_t chunk; off_t bytes_remaining; etaglist_t list; - stringstream strrange; + ostringstream strrange; S3FS_PRN_INFO3("[tpath=%s]", SAFESTRPTR(tpath)); @@ -3814,7 +3814,7 @@ int S3fsCurl::MultipartRenameRequest(const char* from, const char* to, headers_t off_t chunk; off_t bytes_remaining; etaglist_t list; - stringstream strrange; + ostringstream strrange; S3FS_PRN_INFO3("[from=%s][to=%s]", SAFESTRPTR(from), SAFESTRPTR(to)); diff --git a/src/fdcache.cpp b/src/fdcache.cpp index 752b22a..b9f3c5b 100644 --- a/src/fdcache.cpp +++ b/src/fdcache.cpp @@ -503,7 +503,7 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) // // put to file // - stringstream ssall; + ostringstream ssall; ssall << Size(); for(fdpage_list_t::iterator iter = pages.begin(); iter != pages.end(); ++iter){ @@ -543,8 +543,8 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) free(ptmp); return false; } - string oneline; - stringstream ssall(ptmp); + string oneline; + istringstream ssall(ptmp); // loaded Clear(); @@ -560,8 +560,8 @@ bool PageList::Serialize(CacheFileStat& file, bool is_output) // load each part bool is_err = false; while(getline(ssall, oneline, '\n')){ - string part; - stringstream ssparts(oneline); + string part; + istringstream ssparts(oneline); // offset if(!getline(ssparts, part, ':')){ is_err = true; diff --git a/src/s3fs_util.cpp b/src/s3fs_util.cpp index fb092ef..52fdca5 100644 --- a/src/s3fs_util.cpp +++ b/src/s3fs_util.cpp @@ -609,9 +609,9 @@ string mybasename(const string& path) // mkdir --parents int mkdirp(const string& path, mode_t mode) { - string base; - string component; - stringstream ss(path); + string base; + string component; + istringstream ss(path); while (getline(ss, component, '/')) { base += "/" + component; @@ -632,10 +632,10 @@ int mkdirp(const string& path, mode_t mode) // get existed directory path string get_exist_directory_path(const string& path) { - string existed("/"); // "/" is existed. - string base; - string component; - stringstream ss(path); + string existed("/"); // "/" is existed. + string base; + string component; + istringstream ss(path); while (getline(ss, component, '/')) { if(base != "/"){ base += "/"; diff --git a/src/string_util.cpp b/src/string_util.cpp index 720feaa..e998dc1 100644 --- a/src/string_util.cpp +++ b/src/string_util.cpp @@ -33,7 +33,7 @@ using namespace std; template std::string str(T value) { - std::stringstream s; + std::ostringstream s; s << value; return s.str(); }