Code cleanup. Avoid std::string temporaries.

pull/2/head
Tatsuhiro Tsujikawa 2011-11-05 01:11:04 +09:00
parent 150c1ab0c3
commit 1d56c17225
14 changed files with 26 additions and 19 deletions

View File

@ -62,7 +62,7 @@ void DHTMessage::generateTransactionID()
{
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
util::generateRandomData(tid, DHT_TRANSACTION_ID_LENGTH);
transactionID_ = std::string(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
transactionID_.assign(&tid[0], &tid[DHT_TRANSACTION_ID_LENGTH]);
}
} // namespace aria2

View File

@ -137,7 +137,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
(new UTMetadataDataExtensionMessage(extensionMessageID));
m->setIndex(index->i());
m->setTotalSize(totalSize->i());
m->setData(std::string(&data[1+end], &data[length]));
m->setData(&data[1+end], &data[length]);
m->setUTMetadataRequestTracker(tracker_);
m->setPieceStorage(dctx_->getOwnerRequestGroup()->getPieceStorage());
m->setDownloadContext(dctx_);

View File

@ -99,7 +99,7 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
{
unsigned char sessionId[20];
util::generateRandomKey(sessionId);
sessionId_ = std::string(&sessionId[0], & sessionId[sizeof(sessionId)]);
sessionId_.assign(&sessionId[0], & sessionId[sizeof(sessionId)]);
}
DownloadEngine::~DownloadEngine() {

View File

@ -144,7 +144,7 @@ bool File::mkdirs() {
continue;
}
#endif // __MINGW32__
std::string dir = std::string(begin, j);
std::string dir(begin, j);
A2_LOG_DEBUG(fmt("Making directory %s", dir.c_str()));
if(File(dir).isDir()) {
A2_LOG_DEBUG(fmt("%s exists and is a directory.", dir.c_str()));

View File

@ -100,7 +100,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
if(peerConnection_->getBufferLength() >= 48) {
const unsigned char* data = peerConnection_->getBuffer();
// check info_hash
std::string infoHash = std::string(&data[28], &data[28+INFO_HASH_LENGTH]);
std::string infoHash(&data[28], &data[28+INFO_HASH_LENGTH]);
SharedHandle<DownloadContext> downloadContext =
getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash);

View File

@ -1183,15 +1183,15 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
res->uploadLength = st.getAllTimeUploadLength();
if(pieceStorage_) {
if(pieceStorage_->getBitfieldLength() > 0) {
res->bitfield = std::string(pieceStorage_->getBitfield(),
pieceStorage_->getBitfield()+
pieceStorage_->getBitfieldLength());
res->bitfield.assign(pieceStorage_->getBitfield(),
pieceStorage_->getBitfield()+
pieceStorage_->getBitfieldLength());
}
}
#ifdef ENABLE_BITTORRENT
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
const unsigned char* p = bittorrent::getInfoHash(downloadContext_);
res->infoHash = std::string(p, p+INFO_HASH_LENGTH);
res->infoHash.assign(p, p+INFO_HASH_LENGTH);
}
#endif // ENABLE_BITTORRENT
res->pieceLength = downloadContext_->getPieceLength();

View File

@ -1141,7 +1141,8 @@ void getInterfaceAddress
} else {
continue;
}
if(std::string(ifa->ifa_name) == iface) {
if(util::streq(iface.begin(), iface.end(),
ifa->ifa_name, ifa->ifa_name+strlen(ifa->ifa_name))) {
socklen_t bindAddrLen =
iffamily == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
sockaddr_union bindAddr;

View File

@ -77,6 +77,12 @@ public:
void setData(const std::string& data);
template<typename InputIterator>
void setData(InputIterator first, InputIterator last)
{
data_.assign(first, last);
}
const std::string& getData() const
{
return data_;

View File

@ -93,7 +93,7 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
(getIndex()+1)*METADATA_PIECE_SIZE <= attrs->metadata.size()?
attrs->metadata.begin()+(getIndex()+1)*METADATA_PIECE_SIZE:
attrs->metadata.end();
m->setData(std::string(begin, end));
m->setData(begin, end);
SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
dispatcher_->addMessageToQueue(msg);
} else {

View File

@ -86,7 +86,7 @@ void mlStartElement
}
const char* valueBegin = reinterpret_cast<const char*>(attrs[index+3]);
const char* valueEnd = reinterpret_cast<const char*>(attrs[index+4]);
xmlAttr.value = std::string(valueBegin, valueEnd);
xmlAttr.value.assign(valueBegin, valueEnd);
xmlAttrs.push_back(xmlAttr);
}
assert(srcLocalname);

View File

@ -78,7 +78,7 @@ void mlStartElement(void* userData, const xmlChar* name,
}
sd->stm_->beginElement(reinterpret_cast<const char*>(name), attrmap);
if(sd->stm_->needsCharactersBuffering()) {
sd->charactersStack_.push(std::string());
sd->charactersStack_.push(A2STR::NIL);
}
}
} // namespace

View File

@ -426,7 +426,7 @@ void processRootDictionary
MessageDigest::sha1(),
encodedInfoDict.data(),
encodedInfoDict.size());
torrent->infoHash = std::string(&infoHash[0], &infoHash[INFO_HASH_LENGTH]);
torrent->infoHash.assign(&infoHash[0], &infoHash[INFO_HASH_LENGTH]);
torrent->metadata = encodedInfoDict;
torrent->metadataSize = encodedInfoDict.size();

View File

@ -299,7 +299,7 @@ bool parse
if(noDot == end) {
return false;
}
cookieDomain = std::string(noDot, end);
cookieDomain.assign(noDot, end);
} else if(attrName == "path") {
if(goodPath(attrp.first, attrp.second)) {
cookiePath.assign(attrp.first, attrp.second);

View File

@ -728,7 +728,7 @@ void parseParam(OutputIterator out, const std::string& header)
std::string param;
if(paramLast == eoi || *paramLast == ';') {
// No value, parmname only
param = std::string(paramFirst, paramLast);
param.assign(paramFirst, paramLast);
} else {
for(; paramLast != eoi && *paramLast != '"' && *paramLast != ';';
++paramLast);
@ -739,10 +739,10 @@ void parseParam(OutputIterator out, const std::string& header)
if(paramLast != eoi) {
++paramLast;
}
param = std::string(paramFirst, paramLast);
param.assign(paramFirst, paramLast);
for(; paramLast != eoi && *paramLast != ';'; ++paramLast);
} else {
param = std::string(paramFirst, paramLast);
param.assign(paramFirst, paramLast);
}
}
param = strip(param);
@ -1509,7 +1509,7 @@ void executeHook
if(batch) {
const char* p = getenv("windir");
if(p) {
cmdexe = std::string(p);
cmdexe = p;
cmdexe += "\\system32\\cmd.exe";
} else {
A2_LOG_INFO("Failed to get windir environment variable."