summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNils Maier <maierman@web.de>2013-08-25 18:00:46 +0200
committerNils Maier <maierman@web.de>2013-09-20 23:06:49 +0200
commit3590077d5c43d492b3e357d1a50afca4a7d1cfcf (patch)
tree592516aa08b74c7e90c41a9b50c227f3f5b877b0 /src
parenta76eeb2b8106dd725097750c3ee4958e505e3c85 (diff)
More auto-converts by cpp11-migrate
Diffstat (limited to 'src')
-rw-r--r--src/AbstractSingleDiskAdaptor.cc25
-rw-r--r--src/AdaptiveURISelector.cc14
-rw-r--r--src/AppleTLSSession.cc10
-rw-r--r--src/BtAllowedFastMessage.cc4
-rw-r--r--src/BtChokeMessage.cc4
-rw-r--r--src/BtInterestedMessage.cc4
-rw-r--r--src/BtLeecherStateChoke.cc9
-rw-r--r--src/BtNotInterestedMessage.cc4
-rw-r--r--src/BtPieceMessage.cc4
-rw-r--r--src/BtSeederStateChoke.cc9
-rw-r--r--src/BtUnchokeMessage.cc4
-rw-r--r--src/DHTPeerAnnounceStorage.cc6
-rw-r--r--src/DNSCache.cc6
-rw-r--r--src/DefaultBtRequestFactory.cc6
-rw-r--r--src/DefaultPieceStorage.cc2
-rw-r--r--src/ExpatXmlParser.cc27
-rw-r--r--src/FileEntry.cc8
-rw-r--r--src/HttpDownloadCommand.cc1
-rw-r--r--src/HttpRequest.cc7
-rw-r--r--src/IndexBtMessage.cc2
-rw-r--r--src/KqueueEventPoll.cc17
-rw-r--r--src/LibuvEventPoll.cc2
-rw-r--r--src/MessageDigest.cc4
-rw-r--r--src/OptionParser.cc9
-rw-r--r--src/Piece.cc11
-rw-r--r--src/PollEventPoll.cc20
-rw-r--r--src/PriorityPieceSelector.cc7
-rw-r--r--src/RequestGroup.cc6
-rw-r--r--src/RpcResponse.cc12
-rw-r--r--src/SegmentMan.cc23
-rw-r--r--src/SelectEventPoll.cc32
-rw-r--r--src/ServerStatMan.cc12
-rw-r--r--src/SessionSerializer.cc12
-rw-r--r--src/SocketCore.cc10
-rw-r--r--src/Sqlite3CookieParser.cc8
-rw-r--r--src/UTMetadataRequestTracker.cc4
-rw-r--r--src/WrDiskCache.cc2
-rw-r--r--src/WrDiskCacheEntry.cc9
-rw-r--r--src/base32.cc4
-rw-r--r--src/bencode2.cc12
-rw-r--r--src/bittorrent_helper.cc5
-rw-r--r--src/util.cc5
42 files changed, 174 insertions, 208 deletions
diff --git a/src/AbstractSingleDiskAdaptor.cc b/src/AbstractSingleDiskAdaptor.cc
index 90c82ee0..c3a2ba0c 100644
--- a/src/AbstractSingleDiskAdaptor.cc
+++ b/src/AbstractSingleDiskAdaptor.cc
@@ -94,35 +94,34 @@ void AbstractSingleDiskAdaptor::writeCache(const WrDiskCacheEntry* entry)
size_t buflen = 0;
size_t buffoffset = 0;
const WrDiskCacheEntry::DataCellSet& dataSet = entry->getDataSet();
- for(WrDiskCacheEntry::DataCellSet::const_iterator i = dataSet.begin(),
- eoi = dataSet.end(); i != eoi; ++i) {
- if(start+static_cast<ssize_t>(buflen) < (*i)->goff) {
+ for(auto & d : dataSet) {
+ if(start+static_cast<ssize_t>(buflen) < d->goff) {
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
- start = (*i)->goff;
+ start = d->goff;
buflen = buffoffset = 0;
}
- if(buflen == 0 && ((*i)->goff & 0xfff) == 0 && ((*i)->len & 0xfff) == 0) {
+ if(buflen == 0 && (d->goff & 0xfff) == 0 && (d->len & 0xfff) == 0) {
// Already aligned. Write it without copy.
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
- start, static_cast<unsigned long>((*i)->len)));
- writeData((*i)->data + (*i)->offset, (*i)->len, start);
- start += (*i)->len;
+ start, static_cast<unsigned long>(d->len)));
+ writeData(d->data + d->offset, d->len, start);
+ start += d->len;
} else {
if(buflen == 0) {
- buflen = buffoffset = (*i)->goff & 0xfff;
+ buflen = buffoffset = d->goff & 0xfff;
}
- size_t wlen = std::min(sizeof(buf) - buflen, (*i)->len);
- memcpy(buf+buflen, (*i)->data+(*i)->offset, wlen);
+ size_t wlen = std::min(sizeof(buf) - buflen, d->len);
+ memcpy(buf+buflen, d->data + d->offset, wlen);
buflen += wlen;
if(buflen == sizeof(buf)) {
A2_LOG_DEBUG(fmt("Cache flush goff=%" PRId64 ", len=%lu",
start, static_cast<unsigned long>(buflen)));
writeData(buf+buffoffset, buflen-buffoffset, start);
- memcpy(buf, (*i)->data + (*i)->offset + wlen, (*i)->len - wlen);
+ memcpy(buf, d->data + d->offset + wlen, d->len - wlen);
start += sizeof(buf) - buffoffset;
- buflen = (*i)->len - wlen;
+ buflen = d->len - wlen;
buffoffset = 0;
}
}
diff --git a/src/AdaptiveURISelector.cc b/src/AdaptiveURISelector.cc
index 1001247d..5794ac88 100644
--- a/src/AdaptiveURISelector.cc
+++ b/src/AdaptiveURISelector.cc
@@ -263,18 +263,18 @@ std::string AdaptiveURISelector::getMaxDownloadSpeedUri
{
int max = -1;
std::string uri = A2STR::NIL;
- for(auto i = uris.begin(), eoi = uris.end(); i != eoi; ++i) {
- std::shared_ptr<ServerStat> ss = getServerStats(*i);
+ for(auto& u : uris) {
+ std::shared_ptr<ServerStat> ss = getServerStats(u);
if(!ss)
continue;
if((int)ss->getSingleConnectionAvgSpeed() > max) {
max = ss->getSingleConnectionAvgSpeed();
- uri = (*i);
+ uri = u;
}
if((int)ss->getMultiConnectionAvgSpeed() > max) {
max = ss->getMultiConnectionAvgSpeed();
- uri = (*i);
+ uri = u;
}
}
return uri;
@@ -284,13 +284,13 @@ std::deque<std::string> AdaptiveURISelector::getUrisBySpeed
(const std::deque<std::string>& uris, int min) const
{
std::deque<std::string> bests;
- for(auto i = uris.begin(), eoi = uris.end(); i != eoi; ++i) {
- std::shared_ptr<ServerStat> ss = getServerStats(*i);
+ for(auto& uri : uris) {
+ std::shared_ptr<ServerStat> ss = getServerStats(uri);
if(!ss)
continue;
if(ss->getSingleConnectionAvgSpeed() > min ||
ss->getMultiConnectionAvgSpeed() > min) {
- bests.push_back(*i);
+ bests.push_back(uri);
}
}
return bests;
diff --git a/src/AppleTLSSession.cc b/src/AppleTLSSession.cc
index 5c13e569..c59c049b 100644
--- a/src/AppleTLSSession.cc
+++ b/src/AppleTLSSession.cc
@@ -230,9 +230,9 @@ namespace {
static inline const char* suiteToString(const SSLCipherSuite suite)
{
- for (size_t i = 0; i < nSuites; ++i) {
- if (kSuites[i].suite == suite) {
- return kSuites[i].name;
+ for (auto & s : kSuites) {
+ if (s.suite == suite) {
+ return s.name;
}
}
return "Unknown suite";
@@ -246,8 +246,8 @@ namespace {
static inline bool isBlockedSuite(SSLCipherSuite suite)
{
const char* name = suiteToString(suite);
- for (size_t i = 0; i < nBlocked; ++i) {
- if (strstr(name, kBlocked[i])) {
+ for (auto& blocked : kBlocked) {
+ if (strstr(name, blocked)) {
return true;
}
}
diff --git a/src/BtAllowedFastMessage.cc b/src/BtAllowedFastMessage.cc
index ab5e2cdd..9922a624 100644
--- a/src/BtAllowedFastMessage.cc
+++ b/src/BtAllowedFastMessage.cc
@@ -65,8 +65,8 @@ void BtAllowedFastMessage::doReceivedAction() {
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const std::shared_ptr<Peer>& peer, size_t index)
- : peer(peer), index(index) {}
+ ThisProgressUpdate(std::shared_ptr<Peer> peer, size_t index)
+ : peer(std::move(peer)), index(index) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(complete) {
diff --git a/src/BtChokeMessage.cc b/src/BtChokeMessage.cc
index 15569a36..87e5c084 100644
--- a/src/BtChokeMessage.cc
+++ b/src/BtChokeMessage.cc
@@ -67,9 +67,9 @@ bool BtChokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const std::shared_ptr<Peer>& peer,
+ ThisProgressUpdate(std::shared_ptr<Peer> peer,
BtMessageDispatcher* disp)
- : peer(peer), disp(disp) {}
+ : peer(std::move(peer)), disp(disp) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(complete) {
diff --git a/src/BtInterestedMessage.cc b/src/BtInterestedMessage.cc
index a2fbc6b6..2ef30600 100644
--- a/src/BtInterestedMessage.cc
+++ b/src/BtInterestedMessage.cc
@@ -72,8 +72,8 @@ bool BtInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
- : peer(peer) {}
+ ThisProgressUpdate(std::shared_ptr<Peer> peer)
+ : peer(std::move(peer)) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(complete) {
diff --git a/src/BtLeecherStateChoke.cc b/src/BtLeecherStateChoke.cc
index 6533320e..7da3f6b3 100644
--- a/src/BtLeecherStateChoke.cc
+++ b/src/BtLeecherStateChoke.cc
@@ -201,11 +201,10 @@ void BtLeecherStateChoke::executeChoke(const PeerSet& peerSet)
lastRound_ = global::wallclock();
std::vector<PeerEntry> peerEntries;
- for(PeerSet::const_iterator i = peerSet.begin(), eoi = peerSet.end();
- i != eoi; ++i) {
- if((*i)->isActive() && !(*i)->snubbing()) {
- (*i)->chokingRequired(true);
- peerEntries.push_back(PeerEntry(*i));
+ for (const auto& p : peerSet) {
+ if(p->isActive() && !p->snubbing()) {
+ p->chokingRequired(true);
+ peerEntries.push_back(PeerEntry(p));
}
}
diff --git a/src/BtNotInterestedMessage.cc b/src/BtNotInterestedMessage.cc
index 274ec9e6..c79a27de 100644
--- a/src/BtNotInterestedMessage.cc
+++ b/src/BtNotInterestedMessage.cc
@@ -72,8 +72,8 @@ bool BtNotInterestedMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
- : peer(peer) {}
+ ThisProgressUpdate(std::shared_ptr<Peer> peer)
+ : peer(std::move(peer)) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(complete) {
diff --git a/src/BtPieceMessage.cc b/src/BtPieceMessage.cc
index ef08a131..de41b4f1 100644
--- a/src/BtPieceMessage.cc
+++ b/src/BtPieceMessage.cc
@@ -180,8 +180,8 @@ size_t BtPieceMessage::getMessageHeaderLength()
namespace {
struct PieceSendUpdate : public ProgressUpdate {
- PieceSendUpdate(const std::shared_ptr<Peer>& peer, size_t headerLength)
- : peer(peer), headerLength(headerLength) {}
+ PieceSendUpdate(std::shared_ptr<Peer> peer, size_t headerLength)
+ : peer(std::move(peer)), headerLength(headerLength) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(headerLength > 0) {
diff --git a/src/BtSeederStateChoke.cc b/src/BtSeederStateChoke.cc
index b372e69f..dbe7e410 100644
--- a/src/BtSeederStateChoke.cc
+++ b/src/BtSeederStateChoke.cc
@@ -151,11 +151,10 @@ void BtSeederStateChoke::executeChoke(const PeerSet& peerSet)
lastRound_ = global::wallclock();
std::vector<PeerEntry> peerEntries;
- for(PeerSet::const_iterator i = peerSet.begin(), eoi = peerSet.end();
- i != eoi; ++i) {
- if((*i)->isActive() && (*i)->peerInterested()) {
- (*i)->chokingRequired(true);
- peerEntries.push_back(PeerEntry(*i));
+ for(const auto& p : peerSet) {
+ if(p->isActive() && p->peerInterested()) {
+ p->chokingRequired(true);
+ peerEntries.push_back(PeerEntry(p));
}
}
diff --git a/src/BtUnchokeMessage.cc b/src/BtUnchokeMessage.cc
index a2eff67f..e76d053c 100644
--- a/src/BtUnchokeMessage.cc
+++ b/src/BtUnchokeMessage.cc
@@ -63,8 +63,8 @@ bool BtUnchokeMessage::sendPredicate() const
namespace {
struct ThisProgressUpdate : public ProgressUpdate {
- ThisProgressUpdate(const std::shared_ptr<Peer>& peer)
- : peer(peer) {}
+ ThisProgressUpdate(std::shared_ptr<Peer> peer)
+ : peer(std::move(peer)) {}
virtual void update(size_t length, bool complete) CXX11_OVERRIDE
{
if(complete) {
diff --git a/src/DHTPeerAnnounceStorage.cc b/src/DHTPeerAnnounceStorage.cc
index c71f5fc0..169d09a9 100644
--- a/src/DHTPeerAnnounceStorage.cc
+++ b/src/DHTPeerAnnounceStorage.cc
@@ -69,7 +69,7 @@ DHTPeerAnnounceStorage::getPeerAnnounceEntry(const unsigned char* infoHash)
{
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
- DHTPeerAnnounceEntrySet::iterator i = entries_.lower_bound(entry);
+ auto i = entries_.lower_bound(entry);
if(i != entries_.end() &&
memcmp(infoHash, (*i)->getInfoHash(), DHT_ID_LENGTH) == 0) {
@@ -102,7 +102,7 @@ void DHTPeerAnnounceStorage::getPeers(std::vector<std::shared_ptr<Peer> >& peers
{
std::shared_ptr<DHTPeerAnnounceEntry> entry(new DHTPeerAnnounceEntry(infoHash));
- DHTPeerAnnounceEntrySet::iterator i = entries_.find(entry);
+ auto i = entries_.find(entry);
if(i != entries_.end()) {
(*i)->getPeers(peers);
}
@@ -124,7 +124,7 @@ void DHTPeerAnnounceStorage::handleTimeout()
A2_LOG_DEBUG(fmt("Now purge peer announces(%lu entries) which are timed out.",
static_cast<unsigned long>(entries_.size())));
std::for_each(entries_.begin(), entries_.end(), RemoveStalePeerAddrEntry());
- for(DHTPeerAnnounceEntrySet::iterator i = entries_.begin(),
+ for(auto i = entries_.begin(),
eoi = entries_.end(); i != eoi;) {
if((*i)->empty()) {
entries_.erase(i++);
diff --git a/src/DNSCache.cc b/src/DNSCache.cc
index 01b4e4b0..d7f47b0a 100644
--- a/src/DNSCache.cc
+++ b/src/DNSCache.cc
@@ -165,7 +165,7 @@ const std::string& DNSCache::find
(const std::string& hostname, uint16_t port) const
{
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
- CacheEntrySet::iterator i = entries_.find(target);
+ auto i = entries_.find(target);
if(i == entries_.end()) {
return A2STR::NIL;
} else {
@@ -177,7 +177,7 @@ void DNSCache::put
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
- CacheEntrySet::iterator i = entries_.lower_bound(target);
+ auto i = entries_.lower_bound(target);
if(i != entries_.end() && *(*i) == *target) {
(*i)->add(ipaddr);
} else {
@@ -190,7 +190,7 @@ void DNSCache::markBad
(const std::string& hostname, const std::string& ipaddr, uint16_t port)
{
std::shared_ptr<CacheEntry> target(new CacheEntry(hostname, port));
- CacheEntrySet::iterator i = entries_.find(target);
+ auto i = entries_.find(target);
if(i != entries_.end()) {
(*i)->markBad(ipaddr);
}
diff --git a/src/DefaultBtRequestFactory.cc b/src/DefaultBtRequestFactory.cc
index 129b697d..136f7689 100644
--- a/src/DefaultBtRequestFactory.cc
+++ b/src/DefaultBtRequestFactory.cc
@@ -109,10 +109,10 @@ private:
PieceStorage* pieceStorage_;
cuid_t cuid_;
public:
- ProcessChokedPiece(const std::shared_ptr<Peer>& peer,
+ ProcessChokedPiece(std::shared_ptr<Peer> peer,
PieceStorage* pieceStorage,
cuid_t cuid):
- peer_(peer),
+ peer_(std::move(peer)),
pieceStorage_(pieceStorage),
cuid_(cuid)
{}
@@ -131,7 +131,7 @@ class FindChokedPiece {
private:
std::shared_ptr<Peer> peer_;
public:
- FindChokedPiece(const std::shared_ptr<Peer>& peer):peer_(peer) {}
+ FindChokedPiece(std::shared_ptr<Peer> peer):peer_(std::move(peer)) {}
bool operator()(const std::shared_ptr<Piece>& piece)
{
diff --git a/src/DefaultPieceStorage.cc b/src/DefaultPieceStorage.cc
index 84941d0b..ff1495ff 100644
--- a/src/DefaultPieceStorage.cc
+++ b/src/DefaultPieceStorage.cc
@@ -163,7 +163,7 @@ std::shared_ptr<Piece> DefaultPieceStorage::findUsedPiece(size_t index) const
std::shared_ptr<Piece> p(new Piece());
p->setIndex(index);
- UsedPieceSet::iterator i = usedPieces_.find(p);
+ auto i = usedPieces_.find(p);
if(i == usedPieces_.end()) {
p.reset();
return p;
diff --git a/src/ExpatXmlParser.cc b/src/ExpatXmlParser.cc
index c049c65c..36ccec53 100644
--- a/src/ExpatXmlParser.cc
+++ b/src/ExpatXmlParser.cc
@@ -54,7 +54,7 @@ void splitNsName(const char** localname, const char** nsUri, const char* src)
if(sep) {
*localname = sep+1;
size_t nsUriLen = sep-src;
- char* temp = new char[nsUriLen+1];
+ auto temp = new char[nsUriLen + 1];
memcpy(temp, src, nsUriLen);
temp[nsUriLen] = '\0';
*nsUri = temp;
@@ -71,10 +71,10 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
std::vector<XmlAttr> xmlAttrs;
if(attrs) {
const char** p = attrs;
- while(*p != 0) {
+ while(*p) {
XmlAttr xa;
const char* attrNsName = *p++;
- if(*p == 0) {
+ if(!*p) {
break;
}
splitNsName(&xa.localname, &xa.nsUri, attrNsName);
@@ -84,15 +84,14 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
xmlAttrs.push_back(xa);
}
}
- const char* localname = 0;
- const char* prefix = 0;
- const char* nsUri = 0;
+ const char* localname = nullptr;
+ const char* prefix = nullptr;
+ const char* nsUri = nullptr;
splitNsName(&localname, &nsUri, nsName);
sd->psm->beginElement(localname, prefix, nsUri, xmlAttrs);
delete [] nsUri;
- for(std::vector<XmlAttr>::iterator i = xmlAttrs.begin(),
- eoi = xmlAttrs.end(); i != eoi; ++i) {
- delete [] (*i).nsUri;
+ for(auto& a: xmlAttrs) {
+ delete [] a.nsUri;
}
if(sd->psm->needsCharactersBuffering()) {
sd->charactersStack.push_front(A2STR::NIL);
@@ -103,9 +102,9 @@ void mlStartElement(void* userData, const char* nsName, const char** attrs)
namespace {
void mlEndElement(void* userData, const char* nsName)
{
- const char* localname = 0;
- const char* prefix = 0;
- const char* nsUri = 0;
+ const char* localname = nullptr;
+ const char* prefix = nullptr;
+ const char* nsUri = nullptr;
splitNsName(&localname, &nsUri, nsName);
SessionData* sd = reinterpret_cast<SessionData*>(userData);
std::string characters;
@@ -140,7 +139,7 @@ void setupParser(XML_Parser parser, SessionData *sd)
XmlParser::XmlParser(ParserStateMachine* psm)
: psm_(psm),
sessionData_(psm_),
- ctx_(XML_ParserCreateNS(0, static_cast<const XML_Char>('\t'))),
+ ctx_(XML_ParserCreateNS(nullptr, static_cast<const XML_Char>('\t'))),
lastError_(0)
{
setupParser(ctx_, &sessionData_);
@@ -181,7 +180,7 @@ int XmlParser::reset()
{
psm_->reset();
sessionData_.reset();
- XML_Bool rv = XML_ParserReset(ctx_, 0);
+ XML_Bool rv = XML_ParserReset(ctx_, nullptr);
if(rv == XML_FALSE) {
return lastError_ = ERR_RESET;
} else {
diff --git a/src/FileEntry.cc b/src/FileEntry.cc
index 2786619d..6f572bc0 100644
--- a/src/FileEntry.cc
+++ b/src/FileEntry.cc
@@ -197,8 +197,8 @@ FileEntry::getRequest
// sleeping(Request::getWakeTime() < global::wallclock()). If all
// pooled objects are sleeping, return first one. Caller should
// inspect returned object's getWakeTime().
- RequestPool::iterator i = requestPool_.begin();
- RequestPool::iterator eoi = requestPool_.end();
+ auto i = requestPool_.begin();
+ auto eoi = requestPool_.end();
for(; i != eoi; ++i) {
if((*i)->getWakeTime() <= global::wallclock()) {
break;
@@ -494,10 +494,10 @@ bool FileEntry::removeUri(const std::string& uri)
}
spentUris_.erase(itr);
std::shared_ptr<Request> req;
- InFlightRequestSet::iterator riter =
+ auto riter =
findRequestByUri(inFlightRequests_.begin(), inFlightRequests_.end(), uri);
if(riter == inFlightRequests_.end()) {
- RequestPool::iterator riter = findRequestByUri(requestPool_.begin(),
+ auto riter = findRequestByUri(requestPool_.begin(),
requestPool_.end(), uri);
if(riter == requestPool_.end()) {
return true;
diff --git a/src/HttpDownloadCommand.cc b/src/HttpDownloadCommand.cc
index 1a76c88b..fb60add5 100644
--- a/src/HttpDownloadCommand.cc
+++ b/src/HttpDownloadCommand.cc
@@ -32,6 +32,7 @@
* files in the program, then also delete it here.
*/
/* copyright --> */
+
#include "HttpDownloadCommand.h"
#include "RequestGroup.h"
#include "DownloadEngine.h"
diff --git a/src/HttpRequest.cc b/src/HttpRequest.cc
index 32b44b96..efcde2c1 100644
--- a/src/HttpRequest.cc
+++ b/src/HttpRequest.cc
@@ -441,10 +441,9 @@ bool HttpRequest::conditionalRequest() const
if(!ifModSinceHeader_.empty()) {
return true;
}
- for(auto i = headers_.begin(),
- eoi = headers_.end(); i != eoi; ++i) {
- if(util::istartsWith(*i, "if-modified-since") ||
- util::istartsWith(*i, "if-none-match")) {
+ for(auto& h : headers_) {
+ if(util::istartsWith(h, "if-modified-since") ||
+ util::istartsWith(h, "if-none-match")) {
return true;
}
}
diff --git a/src/IndexBtMessage.cc b/src/IndexBtMessage.cc
index 9e2c9752..39f8face 100644
--- a/src/IndexBtMessage.cc
+++ b/src/IndexBtMessage.cc
@@ -47,7 +47,7 @@ unsigned char* IndexBtMessage::createMessage()
* piece index --- index, 4bytes
* total: 9bytes
*/
- auto msg = new unsigned char[MESSAGE_LENGTH];
+ auto msg = new unsigned char[MESSAGE_LENGTH];
bittorrent::createPeerMessageString(msg, MESSAGE_LENGTH, 5, getId());
bittorrent::setIntParam(&msg[5], index_);
return msg;
diff --git a/src/KqueueEventPoll.cc b/src/KqueueEventPoll.cc
index d1610318..b44e83da 100644
--- a/src/KqueueEventPoll.cc
+++ b/src/KqueueEventPoll.cc
@@ -141,11 +141,10 @@ void KqueueEventPoll::poll(const struct timeval& tv)
// own timeout and ares may create new sockets or closes socket in
// their API. So we call ares_process_fd for all ares_channel and
// re-register their sockets.
- for(KAsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
- eoi = nameResolverEntries_.end(); i != eoi; ++i) {
- (*i)->processTimeout();
- (*i)->removeSocketEvents(this);
- (*i)->addSocketEvents(this);
+ for(auto & r : nameResolverEntries_) {
+ r->processTimeout();
+ r->removeSocketEvents(this);
+ r->addSocketEvents(this);
}
#endif // ENABLE_ASYNC_DNS
@@ -171,7 +170,7 @@ bool KqueueEventPoll::addEvents
(sock_t socket, const KqueueEventPoll::KEvent& event)
{
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
- KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
+ auto i = socketEntries_.lower_bound(socketEntry);
int r = 0;
struct timespec zeroTimeout = { 0, 0 };
struct kevent changelist[2];
@@ -220,7 +219,7 @@ bool KqueueEventPoll::deleteEvents(sock_t socket,
const KqueueEventPoll::KEvent& event)
{
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
- KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
+ auto i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
return false;
@@ -266,7 +265,7 @@ bool KqueueEventPoll::addNameResolver
{
std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
- KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
+ auto itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
nameResolverEntries_.insert(entry);
entry->addSocketEvents(this);
@@ -281,7 +280,7 @@ bool KqueueEventPoll::deleteNameResolver
{
std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
- KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
+ auto itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
return false;
} else {
diff --git a/src/LibuvEventPoll.cc b/src/LibuvEventPoll.cc
index 791d8521..201cb384 100644
--- a/src/LibuvEventPoll.cc
+++ b/src/LibuvEventPoll.cc
@@ -223,7 +223,7 @@ bool LibuvEventPoll::addEvents(sock_t socket,
if (i != socketEntries_.end() && **i == *socketEntry) {
event.addSelf(*i);
- KPolls::iterator poll = polls_.find(socket);
+ auto poll = polls_.find(socket);
if (poll == polls_.end()) {
throw std::logic_error("Invalid socket");
}
diff --git a/src/MessageDigest.cc b/src/MessageDigest.cc
index 725c56c8..278baa9b 100644
--- a/src/MessageDigest.cc
+++ b/src/MessageDigest.cc
@@ -47,8 +47,8 @@ namespace {
struct HashTypeEntry {
std::string hashType;
int strength;
- HashTypeEntry(const std::string& hashType, int strength):
- hashType(hashType), strength(strength) {}
+ HashTypeEntry(std::string hashType, int strength):
+ hashType(std::move(hashType)), strength(strength) {}
};
} // namespace
diff --git a/src/OptionParser.cc b/src/OptionParser.cc
index 032f696d..6a56d13d 100644
--- a/src/OptionParser.cc
+++ b/src/OptionParser.cc
@@ -247,14 +247,13 @@ void OptionParser::parse(Option& option, std::istream& is) const
void OptionParser::parse(Option& option, const KeyVals& options) const
{
- for(KeyVals::const_iterator i = options.begin(), eoi = options.end();
- i != eoi; ++i) {
- PrefPtr pref = option::k2p((*i).first);
+ for(const auto& o : options) {
+ auto pref = option::k2p(o.first);
const OptionHandler* handler = find(pref);
if(handler) {
- handler->parse(option, (*i).second);
+ handler->parse(option, o.second);
} else {
- A2_LOG_WARN(fmt("Unknown option: %s", (*i).first.c_str()));
+ A2_LOG_WARN(fmt("Unknown option: %s", o.first.c_str()));
}
}
}
diff --git a/src/Piece.cc b/src/Piece.cc
index 4c3ee4bf..872b8435 100644
--- a/src/Piece.cc
+++ b/src/Piece.cc
@@ -279,13 +279,12 @@ std::string Piece::getDigestWithWrCache
int64_t goff = start;
if(wrCache_) {
const WrDiskCacheEntry::DataCellSet& dataSet = wrCache_->getDataSet();
- for(WrDiskCacheEntry::DataCellSet::iterator i = dataSet.begin(),
- eoi = dataSet.end(); i != eoi; ++i) {
- if(goff < (*i)->goff) {
- updateHashWithRead(mdctx.get(), adaptor, goff, (*i)->goff - goff);
+ for(auto& d : dataSet) {
+ if(goff < d->goff) {
+ updateHashWithRead(mdctx.get(), adaptor, goff, d->goff - goff);
}
- mdctx->update((*i)->data+(*i)->offset, (*i)->len);
- goff = (*i)->goff + (*i)->len;
+ mdctx->update(d->data + d->offset, d->len);
+ goff = d->goff + d->len;
}
updateHashWithRead(mdctx.get(), adaptor, goff, start+length_-goff);
} else {
diff --git a/src/PollEventPoll.cc b/src/PollEventPoll.cc
index d95078dd..5c64ef84 100644
--- a/src/PollEventPoll.cc
+++ b/src/PollEventPoll.cc
@@ -101,7 +101,7 @@ void PollEventPoll::poll(const struct timeval& tv)
first != last; ++first) {
if(first->revents) {
se->setSocket(first->fd);
- KSocketEntrySet::iterator itr = socketEntries_.find(se);
+ auto itr = socketEntries_.find(se);
if(itr == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.",
first->fd));
@@ -119,11 +119,10 @@ void PollEventPoll::poll(const struct timeval& tv)
// own timeout and ares may create new sockets or closes socket in
// their API. So we call ares_process_fd for all ares_channel and
// re-register their sockets.
- for(KAsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
- eoi = nameResolverEntries_.end(); i != eoi; ++i) {
- (*i)->processTimeout();
- (*i)->removeSocketEvents(this);
- (*i)->addSocketEvents(this);
+ for(auto& r : nameResolverEntries_) {
+ r->processTimeout();
+ r->removeSocketEvents(this);
+ r->addSocketEvents(this);
}
#endif // ENABLE_ASYNC_DNS
@@ -153,7 +152,7 @@ bool PollEventPoll::addEvents
(sock_t socket, const PollEventPoll::KEvent& event)
{
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
- KSocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
+ auto i = socketEntries_.lower_bound(socketEntry);
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
event.addSelf(*i);
for(struct pollfd* first = pollfds_, *last = pollfds_+pollfdNum_;
@@ -199,7 +198,7 @@ bool PollEventPoll::deleteEvents
(sock_t socket, const PollEventPoll::KEvent& event)
{
std::shared_ptr<KSocketEntry> socketEntry(new KSocketEntry(socket));
- KSocketEntrySet::iterator i = socketEntries_.find(socketEntry);
+ auto i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
return false;
@@ -245,8 +244,7 @@ bool PollEventPoll::addNameResolver
{
std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
- KAsyncNameResolverEntrySet::iterator itr =
- nameResolverEntries_.lower_bound(entry);
+ auto itr = nameResolverEntries_.lower_bound(entry);
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
return false;
} else {
@@ -261,7 +259,7 @@ bool PollEventPoll::deleteNameResolver
{
std::shared_ptr<KAsyncNameResolverEntry> entry
(new KAsyncNameResolverEntry(resolver, command));
- KAsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.find(entry);
+ auto itr = nameResolverEntries_.find(entry);
if(itr == nameResolverEntries_.end()) {
return false;
} else {
diff --git a/src/PriorityPieceSelector.cc b/src/PriorityPieceSelector.cc
index 5f7774c2..3d026aa9 100644
--- a/src/PriorityPieceSelector.cc
+++ b/src/PriorityPieceSelector.cc
@@ -44,10 +44,9 @@ PriorityPieceSelector::PriorityPieceSelector
bool PriorityPieceSelector::select
(size_t& index, const unsigned char* bitfield, size_t nbits) const
{
- for(auto i = prioritizedPieces_.begin(), eoi = prioritizedPieces_.end();
- i != eoi; ++i) {
- if(bitfield::test(bitfield, nbits, *i)) {
- index = *i;
+ for(auto& p : prioritizedPieces_) {
+ if(bitfield::test(bitfield, nbits, p)) {
+ index = p;
return true;
}
}
diff --git a/src/RequestGroup.cc b/src/RequestGroup.cc
index 0977ee51..95bd1baf 100644
--- a/src/RequestGroup.cc
+++ b/src/RequestGroup.cc
@@ -574,8 +574,7 @@ void RequestGroup::initPieceStorage()
#endif // ENABLE_BITTORRENT
)) {
#ifdef ENABLE_BITTORRENT
- auto ps =
- new DefaultPieceStorage(downloadContext_, option_.get());
+ auto ps = new DefaultPieceStorage(downloadContext_, option_.get());
std::shared_ptr<PieceStorage> psHolder(ps);
if(downloadContext_->hasAttribute(CTX_ATTR_BT)) {
if(isUriSuppliedForRequsetFileEntry
@@ -616,8 +615,7 @@ void RequestGroup::initPieceStorage()
}
tempPieceStorage.swap(psHolder);
} else {
- auto ps =
- new UnknownLengthPieceStorage(downloadContext_);
+ auto ps = new UnknownLengthPieceStorage(downloadContext_);
std::shared_ptr<PieceStorage> psHolder(ps);
if(diskWriterFactory_) {
ps->setDiskWriterFactory(diskWriterFactory_);
diff --git a/src/RpcResponse.cc b/src/RpcResponse.cc
index 9360fb2a..e944e823 100644
--- a/src/RpcResponse.cc
+++ b/src/RpcResponse.cc
@@ -76,9 +76,8 @@ void encodeValue(const ValueBase* value, OutputStream& o)
virtual void visit(const List& v) CXX11_OVERRIDE
{
o_ << "<value><array><data>";
- for(List::ValueType::const_iterator i = v.begin(), eoi = v.end();
- i != eoi; ++i) {
- (*i)->accept(*this);
+ for(const auto& e: v) {
+ e->accept(*this);
}
o_ << "</data></array></value>";
}
@@ -86,10 +85,9 @@ void encodeValue(const ValueBase* value, OutputStream& o)
virtual void visit(const Dict& v) CXX11_OVERRIDE
{
o_ << "<value><struct>";
- for(Dict::ValueType::const_iterator i = v.begin(), eoi = v.end();
- i != eoi; ++i) {
- o_ << "<member><name>" << util::htmlEscape((*i).first) << "</name>";
- (*i).second->accept(*this);
+ for(const auto& e: v) {
+ o_ << "<member><name>" << util::htmlEscape(e.first) << "</name>";
+ e.second->accept(*this);
o_ << "</member>";
}
o_ << "</struct></value>";
diff --git a/src/SegmentMan.cc b/src/SegmentMan.cc
index 691416c3..5c216fce 100644
--- a/src/SegmentMan.cc
+++ b/src/SegmentMan.cc
@@ -302,8 +302,8 @@ void SegmentMan::cancelSegmentInternal
}
void SegmentMan::cancelSegment(cuid_t cuid) {
- for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(),
- eoi = usedSegmentEntries_.end(); itr != eoi;) {
+ for(auto itr = usedSegmentEntries_.begin(), eoi = usedSegmentEntries_.end();
+ itr != eoi;) {
if((*itr)->cuid == cuid) {
cancelSegmentInternal(cuid, (*itr)->segment);
itr = usedSegmentEntries_.erase(itr);
@@ -317,7 +317,7 @@ void SegmentMan::cancelSegment(cuid_t cuid) {
void SegmentMan::cancelSegment
(cuid_t cuid, const std::shared_ptr<Segment>& segment)
{
- for(SegmentEntries::iterator itr = usedSegmentEntries_.begin(),
+ for(auto itr = usedSegmentEntries_.begin(),
eoi = usedSegmentEntries_.end(); itr != eoi;) {
if((*itr)->cuid == cuid && *(*itr)->segment == *segment) {
cancelSegmentInternal(cuid, (*itr)->segment);
@@ -331,9 +331,8 @@ void SegmentMan::cancelSegment
void SegmentMan::cancelAllSegments()
{
- for(auto itr = usedSegmentEntries_.begin(), eoi = usedSegmentEntries_.end();
- itr != eoi; ++itr) {
- cancelSegmentInternal((*itr)->cuid, (*itr)->segment);
+ for(auto& e: usedSegmentEntries_) {
+ cancelSegmentInternal(e->cuid, e->segment);
}
usedSegmentEntries_.clear();
}
@@ -361,9 +360,9 @@ bool SegmentMan::completeSegment
(cuid_t cuid, const std::shared_ptr<Segment>& segment) {
pieceStorage_->completePiece(segment->getPiece());
pieceStorage_->advertisePiece(cuid, segment->getPiece()->getIndex());
- SegmentEntries::iterator itr = std::find_if(usedSegmentEntries_.begin(),
- usedSegmentEntries_.end(),
- FindSegmentEntry(segment));
+ auto itr = std::find_if(usedSegmentEntries_.begin(),
+ usedSegmentEntries_.end(),
+ FindSegmentEntry(segment));
if(itr == usedSegmentEntries_.end()) {
return false;
} else {
@@ -391,9 +390,9 @@ void SegmentMan::registerPeerStat(const std::shared_ptr<PeerStat>& peerStat)
std::shared_ptr<PeerStat> SegmentMan::getPeerStat(cuid_t cuid) const
{
- for(auto i = peerStats_.begin(), eoi = peerStats_.end(); i != eoi; ++i) {
- if((*i)->getCuid() == cuid) {
- return *i;
+ for(auto& e: peerStats_) {
+ if(e->getCuid() == cuid) {
+ return e;
}
}
return nullptr;
diff --git a/src/SelectEventPoll.cc b/src/SelectEventPoll.cc
index 41fe97b3..0aec1051 100644
--- a/src/SelectEventPoll.cc
+++ b/src/SelectEventPoll.cc
@@ -177,9 +177,7 @@ void SelectEventPoll::poll(const struct timeval& tv)
#endif // __MINGW32__
#ifdef ENABLE_ASYNC_DNS
- for(AsyncNameResolverEntrySet::iterator itr = nameResolverEntries_.begin(),
- eoi = nameResolverEntries_.end(); itr != eoi; ++itr) {
- const std::shared_ptr<AsyncNameResolverEntry>& entry = *itr;
+ for(auto& entry : nameResolverEntries_) {
int fd = entry->getFds(&rfds, &wfds);
// TODO force error if fd == 0
if(fdmax_ < fd) {
@@ -198,16 +196,15 @@ void SelectEventPoll::poll(const struct timeval& tv)
#endif // !__MINGW32__
} while(retval == -1 && errno == EINTR);
if(retval > 0) {
- for(SocketEntrySet::iterator i = socketEntries_.begin(),
- eoi = socketEntries_.end(); i != eoi; ++i) {
+ for(auto& e: socketEntries_) {
int events = 0;
- if(FD_ISSET((*i)->getSocket(), &rfds)) {
+ if(FD_ISSET(e->getSocket(), &rfds)) {
events |= EventPoll::EVENT_READ;
}
- if(FD_ISSET((*i)->getSocket(), &wfds)) {
+ if(FD_ISSET(e->getSocket(), &wfds)) {
events |= EventPoll::EVENT_WRITE;
}
- (*i)->processEvents(events);
+ e->processEvents(events);
}
} else if(retval == -1) {
int errNum = errno;
@@ -215,9 +212,8 @@ void SelectEventPoll::poll(const struct timeval& tv)
}
#ifdef ENABLE_ASYNC_DNS
- for(AsyncNameResolverEntrySet::iterator i = nameResolverEntries_.begin(),
- eoi = nameResolverEntries_.end(); i != eoi; ++i) {
- (*i)->process(&rfds, &wfds);
+ for(auto & e: nameResolverEntries_) {
+ e->process(&rfds, &wfds);
}
#endif // ENABLE_ASYNC_DNS
@@ -244,9 +240,8 @@ void SelectEventPoll::updateFdSet()
#endif // !__MINGW32__
FD_ZERO(&rfdset_);
FD_ZERO(&wfdset_);
- for(SocketEntrySet::iterator i = socketEntries_.begin(),
- eoi = socketEntries_.end(); i != eoi; ++i) {
- sock_t fd = (*i)->getSocket();
+ for(auto& e: socketEntries_) {
+ sock_t fd = e->getSocket();
#ifndef __MINGW32__
if(fd < 0 || FD_SETSIZE <= fd) {
A2_LOG_WARN("Detected file descriptor >= FD_SETSIZE or < 0. "
@@ -254,7 +249,7 @@ void SelectEventPoll::updateFdSet()
continue;
}
#endif // !__MINGW32__
- int events = (*i)->getEvents();
+ int events = e->getEvents();
if(events&EventPoll::EVENT_READ) {
#ifdef __MINGW32__
checkFdCountMingw(rfdset_);
@@ -277,7 +272,7 @@ bool SelectEventPoll::addEvents(sock_t socket, Command* command,
EventPoll::EventType events)
{
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
- SocketEntrySet::iterator i = socketEntries_.lower_bound(socketEntry);
+ auto i = socketEntries_.lower_bound(socketEntry);
if(i != socketEntries_.end() && *(*i) == *socketEntry) {
(*i)->addCommandEvent(command, events);
} else {
@@ -292,7 +287,7 @@ bool SelectEventPoll::deleteEvents(sock_t socket, Command* command,
EventPoll::EventType events)
{
std::shared_ptr<SocketEntry> socketEntry(new SocketEntry(socket));
- SocketEntrySet::iterator i = socketEntries_.find(socketEntry);
+ auto i = socketEntries_.find(socketEntry);
if(i == socketEntries_.end()) {
A2_LOG_DEBUG(fmt("Socket %d is not found in SocketEntries.", socket));
return false;
@@ -312,8 +307,7 @@ bool SelectEventPoll::addNameResolver
{
std::shared_ptr<AsyncNameResolverEntry> entry
(new AsyncNameResolverEntry(resolver, command));
- AsyncNameResolverEntrySet::iterator itr =
- nameResolverEntries_.lower_bound(entry);
+ auto itr = nameResolverEntries_.lower_bound(entry);
if(itr != nameResolverEntries_.end() && *(*itr) == *entry) {
return false;
} else {
diff --git a/src/ServerStatMan.cc b/src/ServerStatMan.cc
index d748ab51..2d250670 100644
--- a/src/ServerStatMan.cc
+++ b/src/ServerStatMan.cc
@@ -60,7 +60,7 @@ std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
const std::string& protocol) const
{
std::shared_ptr<ServerStat> ss(new ServerStat(hostname, protocol));
- ServerStatSet::iterator i = serverStats_.find(ss);
+ auto i = serverStats_.find(ss);
if(i == serverStats_.end()) {
return nullptr;
} else {
@@ -70,7 +70,7 @@ std::shared_ptr<ServerStat> ServerStatMan::find(const std::string& hostname,
bool ServerStatMan::add(const std::shared_ptr<ServerStat>& serverStat)
{
- ServerStatSet::iterator i = serverStats_.lower_bound(serverStat);
+ auto i = serverStats_.lower_bound(serverStat);
if(i != serverStats_.end() && *(*i) == *serverStat) {
return false;
} else {
@@ -90,9 +90,8 @@ bool ServerStatMan::save(const std::string& filename) const
filename.c_str()));
return false;
}
- for(ServerStatSet::iterator i = serverStats_.begin(),
- eoi = serverStats_.end(); i != eoi; ++i) {
- std::string l = (*i)->toString();
+ for(auto& e: serverStats_) {
+ std::string l = e->toString();
l += "\n";
if(fp.write(l.data(), l.size()) != l.size()) {
A2_LOG_ERROR(fmt(MSG_WRITING_SERVER_STAT_FILE_FAILED,
@@ -252,8 +251,7 @@ public:
void ServerStatMan::removeStaleServerStat(time_t timeout)
{
FindStaleServerStat finder(timeout);
- for(ServerStatSet::iterator i = serverStats_.begin(),
- eoi = serverStats_.end(); i != eoi;) {
+ for(auto i = serverStats_.begin(), eoi = serverStats_.end(); i != eoi;) {
if(finder(*i)) {
serverStats_.erase(i++);
} else {
diff --git a/src/SessionSerializer.cc b/src/SessionSerializer.cc
index d70cc411..cf02548b 100644
--- a/src/SessionSerializer.cc
+++ b/src/SessionSerializer.cc
@@ -266,9 +266,7 @@ bool SessionSerializer::save(IOFile& fp) const
{
std::set<a2_gid_t> metainfoCache;
const DownloadResultList& results = rgman_->getDownloadResults();
- for(DownloadResultList::const_iterator itr = results.begin(),
- eoi = results.end(); itr != eoi; ++itr) {
- const std::shared_ptr<DownloadResult>& dr = *itr;
+ for(const auto& dr : results) {
if(dr->result == error_code::FINISHED ||
dr->result == error_code::REMOVED) {
if(dr->option->getAsBool(PREF_FORCE_SAVE)) {
@@ -296,9 +294,7 @@ bool SessionSerializer::save(IOFile& fp) const
{
// Save active downloads.
const RequestGroupList& groups = rgman_->getRequestGroups();
- for(RequestGroupList::const_iterator itr = groups.begin(),
- eoi = groups.end(); itr != eoi; ++itr) {
- const std::shared_ptr<RequestGroup>& rg = *itr;
+ for(const auto& rg : groups) {
std::shared_ptr<DownloadResult> dr = rg->createDownloadResult();
bool stopped = dr->result == error_code::FINISHED ||
dr->result == error_code::REMOVED;
@@ -312,9 +308,7 @@ bool SessionSerializer::save(IOFile& fp) const
}
if(saveWaiting_) {
const RequestGroupList& groups = rgman_->getReservedGroups();
- for(RequestGroupList::const_iterator itr = groups.begin(),
- eoi = groups.end(); itr != eoi; ++itr) {
- const std::shared_ptr<RequestGroup>& rg = *itr;
+ for(const auto& rg : groups) {
std::shared_ptr<DownloadResult> result = rg->createDownloadResult();
if(!writeDownloadResult(fp, metainfoCache, result)) {
return false;
diff --git a/src/SocketCore.cc b/src/SocketCore.cc
index 585ec634..1b4018b8 100644
--- a/src/SocketCore.cc
+++ b/src/SocketCore.cc
@@ -1175,9 +1175,9 @@ bool verifyHostname(const std::string& hostname,
if(addrLen == 0) {
return false;
}
- for(auto i = ipAddrs.begin(), eoi = ipAddrs.end(); i != eoi; ++i) {
- if(addrLen == (*i).size() &&
- memcmp(binAddr, (*i).c_str(), addrLen) == 0) {
+ for(auto& ipAddr : ipAddrs) {
+ if(addrLen == ipAddr.size() &&
+ memcmp(binAddr, ipAddr.c_str(), addrLen) == 0) {
return true;
}
}
@@ -1187,8 +1187,8 @@ bool verifyHostname(const std::string& hostname,
if(dnsNames.empty()) {
return util::tlsHostnameMatch(commonName, hostname);
}
- for(auto i = dnsNames.begin(), eoi = dnsNames.end(); i != eoi; ++i) {
- if(util::tlsHostnameMatch(*i, hostname)) {
+ for(auto& dnsName : dnsNames) {
+ if(util::tlsHostnameMatch(dnsName, hostname)) {
return true;
}
}
diff --git a/src/Sqlite3CookieParser.cc b/src/Sqlite3CookieParser.cc
index 10a2cb82..2e11c032 100644
--- a/src/Sqlite3CookieParser.cc
+++ b/src/Sqlite3CookieParser.cc
@@ -48,11 +48,11 @@
namespace aria2 {
-Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename):db_(0)
+Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename) : db_(nullptr)
{
int ret;
#ifdef HAVE_SQLITE3_OPEN_V2
- ret = sqlite3_open_v2(filename.c_str(), &db_, SQLITE_OPEN_READONLY, 0);
+ ret = sqlite3_open_v2(filename.c_str(), &db_, SQLITE_OPEN_READONLY, nullptr);
#else // !HAVE_SQLITE3_OPEN_V2
if(!File(filename).isFile()) {
return;
@@ -61,7 +61,7 @@ Sqlite3CookieParser::Sqlite3CookieParser(const std::string& filename):db_(0)
#endif // !HAVE_SQLITE3_OPEN_V2
if(SQLITE_OK != ret) {
sqlite3_close(db_);
- db_ = 0;
+ db_ = nullptr;
}
}
@@ -146,7 +146,7 @@ std::vector<std::unique_ptr<Cookie>> Sqlite3CookieParser::parse()
throw DL_ABORT_EX(fmt("SQLite3 database is not opened."));
}
auto tcookies = std::vector<std::unique_ptr<Cookie>>{};
- char* sqlite3ErrMsg = 0;
+ char* sqlite3ErrMsg = nullptr;
int ret = sqlite3_exec(db_, getQuery(), cookieRowMapper,
&tcookies, &sqlite3ErrMsg);
std::string errMsg;
diff --git a/src/UTMetadataRequestTracker.cc b/src/UTMetadataRequestTracker.cc
index 382f13dc..c301b354 100644
--- a/src/UTMetadataRequestTracker.cc
+++ b/src/UTMetadataRequestTracker.cc
@@ -108,8 +108,8 @@ size_t UTMetadataRequestTracker::avail() const
std::vector<size_t> UTMetadataRequestTracker::getAllTrackedIndex() const
{
std::vector<size_t> indexes;
- for(auto i = trackedRequests_.begin(), eoi = trackedRequests_.end(); i != eoi; ++i) {
- indexes.push_back((*i).index_);
+ for(auto& e: trackedRequests_) {
+ indexes.push_back(e.index_);
}
return indexes;
}
diff --git a/src/WrDiskCache.cc b/src/WrDiskCache.cc
index 3238a35f..9db39fe2 100644
--- a/src/WrDiskCache.cc
+++ b/src/WrDiskCache.cc
@@ -114,7 +114,7 @@ bool WrDiskCache::update(WrDiskCacheEntry* ent, ssize_t delta)
void WrDiskCache::ensureLimit()
{
while(total_ > limit_) {
- EntrySet::iterator i = set_.begin();
+ auto i = set_.begin();
WrDiskCacheEntry* ent = *i;
A2_LOG_DEBUG(fmt("Force flush cache entry size=%lu, clock=%" PRId64,
static_cast<unsigned long>(ent->getSizeKey()),
diff --git a/src/WrDiskCacheEntry.cc b/src/WrDiskCacheEntry.cc
index 5039a6c3..812c2bca 100644
--- a/src/WrDiskCacheEntry.cc
+++ b/src/WrDiskCacheEntry.cc
@@ -65,10 +65,9 @@ WrDiskCacheEntry::~WrDiskCacheEntry()
void WrDiskCacheEntry::deleteDataCells()
{
- for(DataCellSet::iterator i = set_.begin(), eoi = set_.end(); i != eoi;
- ++i) {
- delete [] (*i)->data;
- delete *i;
+ for(auto& e: set_) {
+ delete [] e->data;
+ delete e;
}
set_.clear();
size_ = 0;
@@ -109,7 +108,7 @@ size_t WrDiskCacheEntry::append(int64_t goff, const unsigned char *data,
if(set_.empty()) {
return 0;
}
- DataCellSet::iterator i = set_.end();
+ auto i = set_.end();
--i;
if(static_cast<int64_t>((*i)->goff + (*i)->len) == goff) {
size_t wlen = std::min((*i)->capacity - (*i)->len, len);
diff --git a/src/base32.cc b/src/base32.cc
index 41fcaa39..ebce5799 100644
--- a/src/base32.cc
+++ b/src/base32.cc
@@ -53,9 +53,9 @@ std::string encode(const std::string& src)
std::string ret;
size_t count = 0;
uint64_t buf = 0;
- for(size_t i = 0; i < src.size(); ++i) {
+ for(const auto& ch: src) {
buf <<= 8;
- buf += src[i]&0xffu;
+ buf += ch & 0xffu;
++count;
if(count == 5) {
char temp[8];
diff --git a/src/bencode2.cc b/src/bencode2.cc
index 8c3dab16..e55b8b6e 100644
--- a/src/bencode2.cc
+++ b/src/bencode2.cc
@@ -100,9 +100,8 @@ std::string encode(const ValueBase* vlb)
virtual void visit(const List& list) CXX11_OVERRIDE
{
out_ << "l";
- for(List::ValueType::const_iterator i = list.begin(), eoi = list.end();
- i != eoi; ++i){
- (*i)->accept(*this);
+ for(const auto& e: list){
+ e->accept(*this);
}
out_ << "e";
}
@@ -110,12 +109,11 @@ std::string encode(const ValueBase* vlb)
virtual void visit(const Dict& dict) CXX11_OVERRIDE
{
out_ << "d";
- for(Dict::ValueType::const_iterator i = dict.begin(), eoi = dict.end();
- i != eoi; ++i){
- const std::string& key = (*i).first;
+ for(const auto& e: dict){
+ auto& key = e.first;
out_ << key.size() << ":";
out_.write(key.data(), key.size());
- (*i).second->accept(*this);
+ e.second->accept(*this);
}
out_ << "e";
}
diff --git a/src/bittorrent_helper.cc b/src/bittorrent_helper.cc
index d4e0d18a..8ea5c5f0 100644
--- a/src/bittorrent_helper.cc
+++ b/src/bittorrent_helper.cc
@@ -999,10 +999,9 @@ std::string torrent2Magnet(const TorrentAttribute* attrs)
uri += util::percentEncode(attrs->name);
}
for(auto & elem : attrs->announceList) {
- for(auto uriIter = elem.begin(),
- eoi2 = elem.end(); uriIter != eoi2; ++uriIter) {
+ for(auto& e: elem) {
uri += "&tr=";
- uri += util::percentEncode(*uriIter);
+ uri += util::percentEncode(e);
}
}
return uri;
diff --git a/src/util.cc b/src/util.cc
index 1836de66..e075dfd0 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -1751,8 +1751,7 @@ std::string escapePath(const std::string& s)
{ '"', '*', ':', '<', '>', '?', '\\', '|' };
#endif // __MINGW32__
std::string d;
- for(std::string::const_iterator i = s.begin(), eoi = s.end(); i != eoi; ++i) {
- unsigned char c = *i;
+ for(const auto& c: s) {
if(in(c, 0x00u, 0x1fu) || c == 0x7fu
#ifdef __MINGW32__
|| std::find(std::begin(WIN_INVALID_PATH_CHARS),
@@ -1762,7 +1761,7 @@ std::string escapePath(const std::string& s)
){
d += fmt("%%%02X", c);
} else {
- d += *i;
+ d += c;
}
}
return d;