Code cleanup. Avoid std::string temporaries.

pull/2/head
Tatsuhiro Tsujikawa 2011-11-05 01:26:09 +09:00
parent 1d56c17225
commit d305432ec0
6 changed files with 11 additions and 12 deletions

View File

@ -395,7 +395,7 @@ bool FtpConnection::bulkReceiveResponse
std::string::size_type length;
if((length = findEndOfResponse(status, strbuf_)) != std::string::npos) {
response.first = status;
response.second = strbuf_.substr(0, length);
response.second.assign(strbuf_.begin(), strbuf_.begin()+length);
A2_LOG_INFO(fmt(MSG_RECEIVE_RESPONSE,
cuid_,
response.second.c_str()));
@ -516,7 +516,7 @@ unsigned int FtpConnection::receivePasvResponse
unsigned int h1, h2, h3, h4, p1, p2;
std::string::size_type p = response.second.find("(");
if(p >= 4) {
sscanf(response.second.substr(response.second.find("(")).c_str(),
sscanf(response.second.c_str()+p,
"(%u,%u,%u,%u,%u,%u).",
&h1, &h2, &h3, &h4, &p1, &p2);
// ip address
@ -549,7 +549,7 @@ unsigned int FtpConnection::receivePwdResponse(std::string& pwd)
if((first = response.second.find("\"")) != std::string::npos &&
(last = response.second.find("\"", ++first)) != std::string::npos) {
pwd = response.second.substr(first, last-first);
pwd.assign(response.second.begin()+first, response.second.begin()+last);
} else {
throw DL_ABORT_EX2(EX_INVALID_RESPONSE,
error_code::FTP_PROTOCOL_ERROR);

View File

@ -116,7 +116,7 @@ SharedHandle<HttpHeader> HttpHeaderProcessor::getHttpResponseHeader()
throw DL_RETRY_EX("Status code could not be parsed as integer.");
}
HttpHeaderHandle httpHeader(new HttpHeader());
httpHeader->setVersion(buf_.substr(0, 8));
httpHeader->setVersion(buf_.begin(), buf_.begin()+8);
httpHeader->setStatusCode(statusCode);
// TODO 1st line(HTTP/1.1 200...) is also send to HttpHeader, but it should
// not.

View File

@ -881,7 +881,7 @@ SharedHandle<TorrentAttribute> parseMagnet(const std::string& magnet)
const String* xt = downcast<String>(*xtiter);
if(util::startsWith(xt->s().begin(), xt->s().end(),
A2_URN_BTIH, vend(A2_URN_BTIH)-1)) {
std::string xtarg = xt->s().substr(9);
std::string xtarg(xt->s().begin()+9, xt->s().end());
size_t size = xtarg.size();
if(size == 32) {
std::string rawhash = base32::decode(xtarg);

View File

@ -139,7 +139,7 @@ bool parseDate
"may", "jun", "jul", "aug",
"sep", "oct", "nov", "dec" };
if((*i).size() >= 3) {
std::string head = (*i).substr(0, 3);
std::string head((*i).begin(), (*i).begin()+3);
util::lowercase(head);
std::string* mptr = std::find(vbegin(MONTH), vend(MONTH), head);
if(mptr != vend(MONTH)) {

View File

@ -118,11 +118,11 @@ void option_processing(Option& op, std::vector<std::string>& uris,
const char A2_HH[] = "--";
if(util::startsWith(keyword.begin(), keyword.end(),
A2_HH, vend(A2_HH)-1)) {
keyword = keyword.substr(2);
keyword.erase(keyword.begin(), keyword.begin()+2);
}
std::string::size_type eqpos = keyword.find("=");
if(eqpos != std::string::npos) {
keyword = keyword.substr(0, eqpos);
keyword.erase(keyword.begin()+eqpos, keyword.end());
}
}
showUsage(keyword, oparser);

View File

@ -238,13 +238,12 @@ std::string replace(const std::string& target, const std::string& oldstr, const
std::string::size_type p = 0;
std::string::size_type np = target.find(oldstr);
while(np != std::string::npos) {
result += target.substr(p, np-p);
result.append(target.begin()+p, target.begin()+np);
result += newstr;
p = np+oldstr.size();
np = target.find(oldstr, p);
}
result += target.substr(p);
result.append(target.begin()+p, target.end());
return result;
}
@ -966,7 +965,7 @@ int64_t getRealSize(const std::string& sizeWithUnit)
} else if(sizeWithUnit[p] == 'M') {
mult = 1024*1024;
}
size = sizeWithUnit.substr(0, p);
size.assign(sizeWithUnit.begin(), sizeWithUnit.begin()+p);
}
int64_t v = parseLLInt(size.begin(), size.end());