mirror of https://github.com/aria2/aria2
Code cleanup. Avoid std::string temporaries.
parent
150c1ab0c3
commit
1d56c17225
|
@ -62,7 +62,7 @@ void DHTMessage::generateTransactionID()
|
||||||
{
|
{
|
||||||
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
|
unsigned char tid[DHT_TRANSACTION_ID_LENGTH];
|
||||||
util::generateRandomData(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
|
} // namespace aria2
|
||||||
|
|
|
@ -137,7 +137,7 @@ DefaultExtensionMessageFactory::createMessage(const unsigned char* data, size_t
|
||||||
(new UTMetadataDataExtensionMessage(extensionMessageID));
|
(new UTMetadataDataExtensionMessage(extensionMessageID));
|
||||||
m->setIndex(index->i());
|
m->setIndex(index->i());
|
||||||
m->setTotalSize(totalSize->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->setUTMetadataRequestTracker(tracker_);
|
||||||
m->setPieceStorage(dctx_->getOwnerRequestGroup()->getPieceStorage());
|
m->setPieceStorage(dctx_->getOwnerRequestGroup()->getPieceStorage());
|
||||||
m->setDownloadContext(dctx_);
|
m->setDownloadContext(dctx_);
|
||||||
|
|
|
@ -99,7 +99,7 @@ DownloadEngine::DownloadEngine(const SharedHandle<EventPoll>& eventPoll)
|
||||||
{
|
{
|
||||||
unsigned char sessionId[20];
|
unsigned char sessionId[20];
|
||||||
util::generateRandomKey(sessionId);
|
util::generateRandomKey(sessionId);
|
||||||
sessionId_ = std::string(&sessionId[0], & sessionId[sizeof(sessionId)]);
|
sessionId_.assign(&sessionId[0], & sessionId[sizeof(sessionId)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DownloadEngine::~DownloadEngine() {
|
DownloadEngine::~DownloadEngine() {
|
||||||
|
|
|
@ -144,7 +144,7 @@ bool File::mkdirs() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
#endif // __MINGW32__
|
#endif // __MINGW32__
|
||||||
std::string dir = std::string(begin, j);
|
std::string dir(begin, j);
|
||||||
A2_LOG_DEBUG(fmt("Making directory %s", dir.c_str()));
|
A2_LOG_DEBUG(fmt("Making directory %s", dir.c_str()));
|
||||||
if(File(dir).isDir()) {
|
if(File(dir).isDir()) {
|
||||||
A2_LOG_DEBUG(fmt("%s exists and is a directory.", dir.c_str()));
|
A2_LOG_DEBUG(fmt("%s exists and is a directory.", dir.c_str()));
|
||||||
|
|
|
@ -100,7 +100,7 @@ bool PeerReceiveHandshakeCommand::executeInternal()
|
||||||
if(peerConnection_->getBufferLength() >= 48) {
|
if(peerConnection_->getBufferLength() >= 48) {
|
||||||
const unsigned char* data = peerConnection_->getBuffer();
|
const unsigned char* data = peerConnection_->getBuffer();
|
||||||
// check info_hash
|
// 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 =
|
SharedHandle<DownloadContext> downloadContext =
|
||||||
getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash);
|
getDownloadEngine()->getBtRegistry()->getDownloadContext(infoHash);
|
||||||
|
|
|
@ -1183,15 +1183,15 @@ DownloadResultHandle RequestGroup::createDownloadResult() const
|
||||||
res->uploadLength = st.getAllTimeUploadLength();
|
res->uploadLength = st.getAllTimeUploadLength();
|
||||||
if(pieceStorage_) {
|
if(pieceStorage_) {
|
||||||
if(pieceStorage_->getBitfieldLength() > 0) {
|
if(pieceStorage_->getBitfieldLength() > 0) {
|
||||||
res->bitfield = std::string(pieceStorage_->getBitfield(),
|
res->bitfield.assign(pieceStorage_->getBitfield(),
|
||||||
pieceStorage_->getBitfield()+
|
pieceStorage_->getBitfield()+
|
||||||
pieceStorage_->getBitfieldLength());
|
pieceStorage_->getBitfieldLength());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#ifdef ENABLE_BITTORRENT
|
#ifdef ENABLE_BITTORRENT
|
||||||
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
|
if(downloadContext_->hasAttribute(bittorrent::BITTORRENT)) {
|
||||||
const unsigned char* p = bittorrent::getInfoHash(downloadContext_);
|
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
|
#endif // ENABLE_BITTORRENT
|
||||||
res->pieceLength = downloadContext_->getPieceLength();
|
res->pieceLength = downloadContext_->getPieceLength();
|
||||||
|
|
|
@ -1141,7 +1141,8 @@ void getInterfaceAddress
|
||||||
} else {
|
} else {
|
||||||
continue;
|
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 =
|
socklen_t bindAddrLen =
|
||||||
iffamily == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
|
iffamily == AF_INET ? sizeof(sockaddr_in) : sizeof(sockaddr_in6);
|
||||||
sockaddr_union bindAddr;
|
sockaddr_union bindAddr;
|
||||||
|
|
|
@ -77,6 +77,12 @@ public:
|
||||||
|
|
||||||
void setData(const std::string& data);
|
void setData(const std::string& data);
|
||||||
|
|
||||||
|
template<typename InputIterator>
|
||||||
|
void setData(InputIterator first, InputIterator last)
|
||||||
|
{
|
||||||
|
data_.assign(first, last);
|
||||||
|
}
|
||||||
|
|
||||||
const std::string& getData() const
|
const std::string& getData() const
|
||||||
{
|
{
|
||||||
return data_;
|
return data_;
|
||||||
|
|
|
@ -93,7 +93,7 @@ void UTMetadataRequestExtensionMessage::doReceivedAction()
|
||||||
(getIndex()+1)*METADATA_PIECE_SIZE <= attrs->metadata.size()?
|
(getIndex()+1)*METADATA_PIECE_SIZE <= attrs->metadata.size()?
|
||||||
attrs->metadata.begin()+(getIndex()+1)*METADATA_PIECE_SIZE:
|
attrs->metadata.begin()+(getIndex()+1)*METADATA_PIECE_SIZE:
|
||||||
attrs->metadata.end();
|
attrs->metadata.end();
|
||||||
m->setData(std::string(begin, end));
|
m->setData(begin, end);
|
||||||
SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
|
SharedHandle<BtMessage> msg = messageFactory_->createBtExtendedMessage(m);
|
||||||
dispatcher_->addMessageToQueue(msg);
|
dispatcher_->addMessageToQueue(msg);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -86,7 +86,7 @@ void mlStartElement
|
||||||
}
|
}
|
||||||
const char* valueBegin = reinterpret_cast<const char*>(attrs[index+3]);
|
const char* valueBegin = reinterpret_cast<const char*>(attrs[index+3]);
|
||||||
const char* valueEnd = reinterpret_cast<const char*>(attrs[index+4]);
|
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);
|
xmlAttrs.push_back(xmlAttr);
|
||||||
}
|
}
|
||||||
assert(srcLocalname);
|
assert(srcLocalname);
|
||||||
|
|
|
@ -78,7 +78,7 @@ void mlStartElement(void* userData, const xmlChar* name,
|
||||||
}
|
}
|
||||||
sd->stm_->beginElement(reinterpret_cast<const char*>(name), attrmap);
|
sd->stm_->beginElement(reinterpret_cast<const char*>(name), attrmap);
|
||||||
if(sd->stm_->needsCharactersBuffering()) {
|
if(sd->stm_->needsCharactersBuffering()) {
|
||||||
sd->charactersStack_.push(std::string());
|
sd->charactersStack_.push(A2STR::NIL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
|
@ -426,7 +426,7 @@ void processRootDictionary
|
||||||
MessageDigest::sha1(),
|
MessageDigest::sha1(),
|
||||||
encodedInfoDict.data(),
|
encodedInfoDict.data(),
|
||||||
encodedInfoDict.size());
|
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->metadata = encodedInfoDict;
|
||||||
torrent->metadataSize = encodedInfoDict.size();
|
torrent->metadataSize = encodedInfoDict.size();
|
||||||
|
|
||||||
|
|
|
@ -299,7 +299,7 @@ bool parse
|
||||||
if(noDot == end) {
|
if(noDot == end) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
cookieDomain = std::string(noDot, end);
|
cookieDomain.assign(noDot, end);
|
||||||
} else if(attrName == "path") {
|
} else if(attrName == "path") {
|
||||||
if(goodPath(attrp.first, attrp.second)) {
|
if(goodPath(attrp.first, attrp.second)) {
|
||||||
cookiePath.assign(attrp.first, attrp.second);
|
cookiePath.assign(attrp.first, attrp.second);
|
||||||
|
|
|
@ -728,7 +728,7 @@ void parseParam(OutputIterator out, const std::string& header)
|
||||||
std::string param;
|
std::string param;
|
||||||
if(paramLast == eoi || *paramLast == ';') {
|
if(paramLast == eoi || *paramLast == ';') {
|
||||||
// No value, parmname only
|
// No value, parmname only
|
||||||
param = std::string(paramFirst, paramLast);
|
param.assign(paramFirst, paramLast);
|
||||||
} else {
|
} else {
|
||||||
for(; paramLast != eoi && *paramLast != '"' && *paramLast != ';';
|
for(; paramLast != eoi && *paramLast != '"' && *paramLast != ';';
|
||||||
++paramLast);
|
++paramLast);
|
||||||
|
@ -739,10 +739,10 @@ void parseParam(OutputIterator out, const std::string& header)
|
||||||
if(paramLast != eoi) {
|
if(paramLast != eoi) {
|
||||||
++paramLast;
|
++paramLast;
|
||||||
}
|
}
|
||||||
param = std::string(paramFirst, paramLast);
|
param.assign(paramFirst, paramLast);
|
||||||
for(; paramLast != eoi && *paramLast != ';'; ++paramLast);
|
for(; paramLast != eoi && *paramLast != ';'; ++paramLast);
|
||||||
} else {
|
} else {
|
||||||
param = std::string(paramFirst, paramLast);
|
param.assign(paramFirst, paramLast);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
param = strip(param);
|
param = strip(param);
|
||||||
|
@ -1509,7 +1509,7 @@ void executeHook
|
||||||
if(batch) {
|
if(batch) {
|
||||||
const char* p = getenv("windir");
|
const char* p = getenv("windir");
|
||||||
if(p) {
|
if(p) {
|
||||||
cmdexe = std::string(p);
|
cmdexe = p;
|
||||||
cmdexe += "\\system32\\cmd.exe";
|
cmdexe += "\\system32\\cmd.exe";
|
||||||
} else {
|
} else {
|
||||||
A2_LOG_INFO("Failed to get windir environment variable."
|
A2_LOG_INFO("Failed to get windir environment variable."
|
||||||
|
|
Loading…
Reference in New Issue