Prefer specific [io]stringstream where possible

These better communicate intent and are slightly more efficient.
This commit is contained in:
Andrew Gaul 2019-01-29 10:44:33 -08:00
parent a442e843be
commit 07636c8a8d
5 changed files with 23 additions and 23 deletions

View File

@ -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;

View File

@ -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<headers_t*>(userPtr);
string header(reinterpret_cast<char*>(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));

View File

@ -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;

View File

@ -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 += "/";

View File

@ -33,7 +33,7 @@
using namespace std;
template <class T> std::string str(T value) {
std::stringstream s;
std::ostringstream s;
s << value;
return s.str();
}