mirror of https://github.com/aria2/aria2
Use binary search in BtDependency for efficiency.
parent
d1bb828066
commit
53fd815111
|
@ -74,6 +74,17 @@ void copyValues(const SharedHandle<FileEntry>& d,
|
||||||
}
|
}
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
struct EntryCmp {
|
||||||
|
bool operator()
|
||||||
|
(const SharedHandle<FileEntry>& lhs,
|
||||||
|
const SharedHandle<FileEntry>& rhs) const
|
||||||
|
{
|
||||||
|
return lhs->getOriginalName() < rhs->getOriginalName();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
} // namespace
|
||||||
|
|
||||||
bool BtDependency::resolve()
|
bool BtDependency::resolve()
|
||||||
{
|
{
|
||||||
if(!dependee_) {
|
if(!dependee_) {
|
||||||
|
@ -115,31 +126,33 @@ bool BtDependency::resolve()
|
||||||
dependantFileEntries[0]->getOriginalName().empty()) {
|
dependantFileEntries[0]->getOriginalName().empty()) {
|
||||||
copyValues(fileEntries[0], dependantFileEntries[0]);
|
copyValues(fileEntries[0], dependantFileEntries[0]);
|
||||||
} else {
|
} else {
|
||||||
std::for_each(fileEntries.begin(), fileEntries.end(),
|
std::vector<SharedHandle<FileEntry> > destFiles;
|
||||||
std::bind2nd(mem_fun_sh(&FileEntry::setRequested),false));
|
destFiles.reserve(fileEntries.size());
|
||||||
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator i =
|
||||||
|
fileEntries.begin(), eoi = fileEntries.end(); i != eoi; ++i) {
|
||||||
|
(*i)->setRequested(false);
|
||||||
|
destFiles.push_back(*i);
|
||||||
|
}
|
||||||
|
std::sort(destFiles.begin(), destFiles.end(), 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.
|
||||||
std::vector<SharedHandle<FileEntry> >::const_iterator ctxFilesEnd =
|
|
||||||
fileEntries.end();
|
|
||||||
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
|
for(std::vector<SharedHandle<FileEntry> >::const_iterator s =
|
||||||
dependantFileEntries.begin(), eoi = dependantFileEntries.end();
|
dependantFileEntries.begin(), eoi = dependantFileEntries.end();
|
||||||
s != eoi; ++s){
|
s != eoi; ++s){
|
||||||
std::vector<SharedHandle<FileEntry> >::const_iterator d =
|
std::vector<SharedHandle<FileEntry> >::const_iterator d =
|
||||||
fileEntries.begin();
|
std::lower_bound(destFiles.begin(), destFiles.end(), *s,
|
||||||
for(; d != ctxFilesEnd; ++d) {
|
EntryCmp());
|
||||||
if((*d)->getOriginalName() == (*s)->getOriginalName()) {
|
if(d == destFiles.end() ||
|
||||||
break;
|
(*d)->getOriginalName() != (*s)->getOriginalName()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
if(d == ctxFilesEnd) {
|
|
||||||
throw DL_ABORT_EX
|
throw DL_ABORT_EX
|
||||||
(fmt("No entry %s in torrent file",
|
(fmt("No entry %s in torrent file",
|
||||||
(*s)->getOriginalName().c_str()));
|
(*s)->getOriginalName().c_str()));
|
||||||
}
|
} else {
|
||||||
copyValues(*d, *s);
|
copyValues(*d, *s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} catch(RecoverableException& e) {
|
} catch(RecoverableException& e) {
|
||||||
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
A2_LOG_ERROR_EX(EX_EXCEPTION_CAUGHT, e);
|
||||||
A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.",
|
A2_LOG_INFO(fmt("BtDependency for GID#%lld failed. Go without Bt.",
|
||||||
|
|
Loading…
Reference in New Issue