Use std::begin and std::end

pull/454/head
Tatsuhiro Tsujikawa 2015-06-11 23:51:41 +09:00
parent 37c2edd97a
commit 377eb0699f
5 changed files with 29 additions and 28 deletions

View File

@ -68,8 +68,8 @@ void copyValues(const std::shared_ptr<FileEntry>& d,
{ {
d->setRequested(true); d->setRequested(true);
d->setPath(s->getPath()); d->setPath(s->getPath());
d->addUris(s->getRemainingUris().begin(), d->addUris(std::begin(s->getRemainingUris()),
s->getRemainingUris().end()); std::end(s->getRemainingUris()));
d->setMaxConnectionPerServer(s->getMaxConnectionPerServer()); d->setMaxConnectionPerServer(s->getMaxConnectionPerServer());
d->setUniqueProtocol(s->isUniqueProtocol()); d->setUniqueProtocol(s->isUniqueProtocol());
} }
@ -138,14 +138,14 @@ bool BtDependency::resolve()
e->setRequested(false); e->setRequested(false);
destFiles.push_back(e); destFiles.push_back(e);
} }
std::sort(destFiles.begin(), destFiles.end(), EntryCmp()); std::sort(std::begin(destFiles), std::end(destFiles), EntryCmp());
// Copy file path in dependant_'s FileEntries to newly created // Copy file path in dependant_'s FileEntries to newly created
// context's FileEntries to endorse the path structure of // context's FileEntries to endorse the path structure of
// dependant_. URIs and singleHostMultiConnection are also copied. // dependant_. URIs and singleHostMultiConnection are also copied.
for(const auto& e: dependantFileEntries){ for(const auto& e: dependantFileEntries){
const auto d = std::lower_bound(destFiles.begin(), destFiles.end(), e, const auto d = std::lower_bound(std::begin(destFiles),
EntryCmp()); std::end(destFiles), e, EntryCmp());
if(d == destFiles.end() || if(d == std::end(destFiles) ||
(*d)->getOriginalName() != e->getOriginalName()) { (*d)->getOriginalName() != e->getOriginalName()) {
throw DL_ABORT_EX throw DL_ABORT_EX
(fmt("No entry %s in torrent file", e->getOriginalName().c_str())); (fmt("No entry %s in torrent file", e->getOriginalName().c_str()));

View File

@ -70,7 +70,7 @@ void BtFileAllocationEntry::prepareForNextAction
const std::vector<std::shared_ptr<FileEntry> >& fileEntries = const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
getRequestGroup()->getDownloadContext()->getFileEntries(); getRequestGroup()->getDownloadContext()->getFileEntries();
if(isUriSuppliedForRequsetFileEntry if(isUriSuppliedForRequsetFileEntry
(fileEntries.begin(), fileEntries.end())) { (std::begin(fileEntries), std::end(fileEntries))) {
getRequestGroup()->createNextCommandWithAdj(commands, e, 0); getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
} }
} else { } else {

View File

@ -146,31 +146,32 @@ bool BtLeecherStateChoke::PeerFilter::operator()
void BtLeecherStateChoke::plannedOptimisticUnchoke void BtLeecherStateChoke::plannedOptimisticUnchoke
(std::vector<PeerEntry>& peerEntries) (std::vector<PeerEntry>& peerEntries)
{ {
std::for_each(peerEntries.begin(), peerEntries.end(), std::for_each(std::begin(peerEntries), std::end(peerEntries),
std::mem_fn(&PeerEntry::disableOptUnchoking)); std::mem_fn(&PeerEntry::disableOptUnchoking));
auto i = std::partition(peerEntries.begin(), peerEntries.end(), auto i = std::partition(std::begin(peerEntries), std::end(peerEntries),
PeerFilter(true, true)); PeerFilter(true, true));
if(i != peerEntries.begin()) { if(i != std::begin(peerEntries)) {
std::shuffle(peerEntries.begin(), i, *SimpleRandomizer::getInstance()); std::shuffle(std::begin(peerEntries), i, *SimpleRandomizer::getInstance());
(*peerEntries.begin()).enableOptUnchoking(); (*std::begin(peerEntries)).enableOptUnchoking();
A2_LOG_INFO(fmt("POU: %s", A2_LOG_INFO(
(*peerEntries.begin()).getPeer()->getIPAddress().c_str())); fmt("POU: %s",
(*std::begin(peerEntries)).getPeer()->getIPAddress().c_str()));
} }
} }
void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries) void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
{ {
auto rest = std::partition(peerEntries.begin(), peerEntries.end(), auto rest = std::partition(std::begin(peerEntries), std::end(peerEntries),
std::mem_fn(&PeerEntry::isRegularUnchoker)); std::mem_fn(&PeerEntry::isRegularUnchoker));
std::sort(peerEntries.begin(), rest); std::sort(std::begin(peerEntries), rest);
// the number of regular unchokers // the number of regular unchokers
int count = 3; int count = 3;
bool fastOptUnchoker = false; bool fastOptUnchoker = false;
auto peerIter = peerEntries.begin(); auto peerIter = std::begin(peerEntries);
for(;peerIter != rest && count; ++peerIter, --count) { for(;peerIter != rest && count; ++peerIter, --count) {
peerIter->disableChokingRequired(); peerIter->disableChokingRequired();
A2_LOG_INFO(fmt("RU: %s, dlspd=%d", A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
@ -182,7 +183,8 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
} }
} }
if(fastOptUnchoker) { if(fastOptUnchoker) {
std::shuffle(peerIter, peerEntries.end(), *SimpleRandomizer::getInstance()); std::shuffle(peerIter, std::end(peerEntries),
*SimpleRandomizer::getInstance());
for (auto& p : peerEntries) { for (auto& p : peerEntries) {
if(p.getPeer()->peerInterested()) { if(p.getPeer()->peerInterested()) {
p.enableOptUnchoking(); p.enableOptUnchoking();

View File

@ -102,12 +102,12 @@ void BtPostDownloadHandler::getNextRequestGroups
std::vector<std::string>(), std::vector<std::string>(),
"", "",
torrent.get()); torrent.get());
requestGroup->followedBy(newRgs.begin(), newRgs.end()); requestGroup->followedBy(std::begin(newRgs), std::end(newRgs));
auto mi = auto mi =
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(), createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
requestGroup->getDownloadContext()); requestGroup->getDownloadContext());
if(mi) { if(mi) {
setMetadataInfo(newRgs.begin(), newRgs.end(), mi); setMetadataInfo(std::begin(newRgs), std::end(newRgs), mi);
} }
auto rgman = requestGroup->getRequestGroupMan(); auto rgman = requestGroup->getRequestGroupMan();
@ -119,7 +119,7 @@ void BtPostDownloadHandler::getNextRequestGroups
} }
} }
groups.insert(groups.end(), newRgs.begin(), newRgs.end()); groups.insert(std::end(groups), std::begin(newRgs), std::end(newRgs));
} }
} // namespace aria2 } // namespace aria2

View File

@ -126,11 +126,10 @@ void BtSeederStateChoke::unchoke
{ {
int count = (round_ == 2) ? 4 : 3; int count = (round_ == 2) ? 4 : 3;
std::sort(peers.begin(), peers.end()); std::sort(std::begin(peers), std::end(peers));
auto r = peers.begin(); auto r = std::begin(peers);
for(auto eoi = peers.end(); for(; r != std::end(peers) && count; ++r, --count) {
r != eoi && count; ++r, --count) {
(*r).getPeer()->chokingRequired(false); (*r).getPeer()->chokingRequired(false);
A2_LOG_INFO(fmt("RU: %s, ulspd=%d", A2_LOG_INFO(fmt("RU: %s, ulspd=%d",
(*r).getPeer()->getIPAddress().c_str(), (*r).getPeer()->getIPAddress().c_str(),
@ -138,10 +137,10 @@ void BtSeederStateChoke::unchoke
} }
if(round_ < 2) { if(round_ < 2) {
std::for_each(peers.begin(), peers.end(), std::for_each(std::begin(peers), std::end(peers),
std::mem_fn(&PeerEntry::disableOptUnchoking)); std::mem_fn(&PeerEntry::disableOptUnchoking));
if(r != peers.end()) { if(r != std::end(peers)) {
std::shuffle(r, peers.end(), *SimpleRandomizer::getInstance()); std::shuffle(r, std::end(peers), *SimpleRandomizer::getInstance());
(*r).getPeer()->optUnchoking(true); (*r).getPeer()->optUnchoking(true);
A2_LOG_INFO(fmt("POU: %s", (*r).getPeer()->getIPAddress().c_str())); A2_LOG_INFO(fmt("POU: %s", (*r).getPeer()->getIPAddress().c_str()));
} }