mirror of https://github.com/aria2/aria2
Use std::begin and std::end
parent
37c2edd97a
commit
377eb0699f
|
@ -68,8 +68,8 @@ void copyValues(const std::shared_ptr<FileEntry>& d,
|
|||
{
|
||||
d->setRequested(true);
|
||||
d->setPath(s->getPath());
|
||||
d->addUris(s->getRemainingUris().begin(),
|
||||
s->getRemainingUris().end());
|
||||
d->addUris(std::begin(s->getRemainingUris()),
|
||||
std::end(s->getRemainingUris()));
|
||||
d->setMaxConnectionPerServer(s->getMaxConnectionPerServer());
|
||||
d->setUniqueProtocol(s->isUniqueProtocol());
|
||||
}
|
||||
|
@ -138,14 +138,14 @@ bool BtDependency::resolve()
|
|||
e->setRequested(false);
|
||||
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
|
||||
// context's FileEntries to endorse the path structure of
|
||||
// dependant_. URIs and singleHostMultiConnection are also copied.
|
||||
for(const auto& e: dependantFileEntries){
|
||||
const auto d = std::lower_bound(destFiles.begin(), destFiles.end(), e,
|
||||
EntryCmp());
|
||||
if(d == destFiles.end() ||
|
||||
const auto d = std::lower_bound(std::begin(destFiles),
|
||||
std::end(destFiles), e, EntryCmp());
|
||||
if(d == std::end(destFiles) ||
|
||||
(*d)->getOriginalName() != e->getOriginalName()) {
|
||||
throw DL_ABORT_EX
|
||||
(fmt("No entry %s in torrent file", e->getOriginalName().c_str()));
|
||||
|
|
|
@ -70,7 +70,7 @@ void BtFileAllocationEntry::prepareForNextAction
|
|||
const std::vector<std::shared_ptr<FileEntry> >& fileEntries =
|
||||
getRequestGroup()->getDownloadContext()->getFileEntries();
|
||||
if(isUriSuppliedForRequsetFileEntry
|
||||
(fileEntries.begin(), fileEntries.end())) {
|
||||
(std::begin(fileEntries), std::end(fileEntries))) {
|
||||
getRequestGroup()->createNextCommandWithAdj(commands, e, 0);
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -146,31 +146,32 @@ bool BtLeecherStateChoke::PeerFilter::operator()
|
|||
void BtLeecherStateChoke::plannedOptimisticUnchoke
|
||||
(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));
|
||||
|
||||
auto i = std::partition(peerEntries.begin(), peerEntries.end(),
|
||||
auto i = std::partition(std::begin(peerEntries), std::end(peerEntries),
|
||||
PeerFilter(true, true));
|
||||
if(i != peerEntries.begin()) {
|
||||
std::shuffle(peerEntries.begin(), i, *SimpleRandomizer::getInstance());
|
||||
(*peerEntries.begin()).enableOptUnchoking();
|
||||
A2_LOG_INFO(fmt("POU: %s",
|
||||
(*peerEntries.begin()).getPeer()->getIPAddress().c_str()));
|
||||
if(i != std::begin(peerEntries)) {
|
||||
std::shuffle(std::begin(peerEntries), i, *SimpleRandomizer::getInstance());
|
||||
(*std::begin(peerEntries)).enableOptUnchoking();
|
||||
A2_LOG_INFO(
|
||||
fmt("POU: %s",
|
||||
(*std::begin(peerEntries)).getPeer()->getIPAddress().c_str()));
|
||||
}
|
||||
}
|
||||
|
||||
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::sort(peerEntries.begin(), rest);
|
||||
std::sort(std::begin(peerEntries), rest);
|
||||
|
||||
// the number of regular unchokers
|
||||
int count = 3;
|
||||
|
||||
bool fastOptUnchoker = false;
|
||||
auto peerIter = peerEntries.begin();
|
||||
auto peerIter = std::begin(peerEntries);
|
||||
for(;peerIter != rest && count; ++peerIter, --count) {
|
||||
peerIter->disableChokingRequired();
|
||||
A2_LOG_INFO(fmt("RU: %s, dlspd=%d",
|
||||
|
@ -182,7 +183,8 @@ void BtLeecherStateChoke::regularUnchoke(std::vector<PeerEntry>& peerEntries)
|
|||
}
|
||||
}
|
||||
if(fastOptUnchoker) {
|
||||
std::shuffle(peerIter, peerEntries.end(), *SimpleRandomizer::getInstance());
|
||||
std::shuffle(peerIter, std::end(peerEntries),
|
||||
*SimpleRandomizer::getInstance());
|
||||
for (auto& p : peerEntries) {
|
||||
if(p.getPeer()->peerInterested()) {
|
||||
p.enableOptUnchoking();
|
||||
|
|
|
@ -102,12 +102,12 @@ void BtPostDownloadHandler::getNextRequestGroups
|
|||
std::vector<std::string>(),
|
||||
"",
|
||||
torrent.get());
|
||||
requestGroup->followedBy(newRgs.begin(), newRgs.end());
|
||||
requestGroup->followedBy(std::begin(newRgs), std::end(newRgs));
|
||||
auto mi =
|
||||
createMetadataInfoFromFirstFileEntry(requestGroup->getGroupId(),
|
||||
requestGroup->getDownloadContext());
|
||||
if(mi) {
|
||||
setMetadataInfo(newRgs.begin(), newRgs.end(), mi);
|
||||
setMetadataInfo(std::begin(newRgs), std::end(newRgs), mi);
|
||||
}
|
||||
|
||||
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
|
||||
|
|
|
@ -126,11 +126,10 @@ void BtSeederStateChoke::unchoke
|
|||
{
|
||||
int count = (round_ == 2) ? 4 : 3;
|
||||
|
||||
std::sort(peers.begin(), peers.end());
|
||||
std::sort(std::begin(peers), std::end(peers));
|
||||
|
||||
auto r = peers.begin();
|
||||
for(auto eoi = peers.end();
|
||||
r != eoi && count; ++r, --count) {
|
||||
auto r = std::begin(peers);
|
||||
for(; r != std::end(peers) && count; ++r, --count) {
|
||||
(*r).getPeer()->chokingRequired(false);
|
||||
A2_LOG_INFO(fmt("RU: %s, ulspd=%d",
|
||||
(*r).getPeer()->getIPAddress().c_str(),
|
||||
|
@ -138,10 +137,10 @@ void BtSeederStateChoke::unchoke
|
|||
}
|
||||
|
||||
if(round_ < 2) {
|
||||
std::for_each(peers.begin(), peers.end(),
|
||||
std::for_each(std::begin(peers), std::end(peers),
|
||||
std::mem_fn(&PeerEntry::disableOptUnchoking));
|
||||
if(r != peers.end()) {
|
||||
std::shuffle(r, peers.end(), *SimpleRandomizer::getInstance());
|
||||
if(r != std::end(peers)) {
|
||||
std::shuffle(r, std::end(peers), *SimpleRandomizer::getInstance());
|
||||
(*r).getPeer()->optUnchoking(true);
|
||||
A2_LOG_INFO(fmt("POU: %s", (*r).getPeer()->getIPAddress().c_str()));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue