From 95586f594f2fc0b873cff2e4daedf26d02abcff5 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Sun, 30 Oct 2011 15:04:15 +0900 Subject: [PATCH] Use SegList instead of IntSequence in Metalink2RequestGroup. --- src/Metalink2RequestGroup.cc | 47 ++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 21 deletions(-) diff --git a/src/Metalink2RequestGroup.cc b/src/Metalink2RequestGroup.cc index 7f97e894..4829355d 100644 --- a/src/Metalink2RequestGroup.cc +++ b/src/Metalink2RequestGroup.cc @@ -56,6 +56,7 @@ #include "a2functional.h" #include "download_helper.h" #include "fmt.h" +#include "SegList.h" #ifdef ENABLE_BITTORRENT # include "BtDependency.h" # include "download_helper.h" @@ -153,9 +154,6 @@ Metalink2RequestGroup::createRequestGroup A2_LOG_NOTICE(EX_NO_RESULT_WITH_YOUR_PREFS); return; } - std::vector selectIndexes = - util::parseIntRange(optionTemplate->get(PREF_SELECT_FILE)).flush(); - std::sort(selectIndexes.begin(), selectIndexes.end()); std::vector locations; if(optionTemplate->defined(PREF_METALINK_LOCATION)) { util::split(util::toLower(optionTemplate->get(PREF_METALINK_LOCATION)), @@ -165,25 +163,32 @@ Metalink2RequestGroup::createRequestGroup if(optionTemplate->get(PREF_METALINK_PREFERRED_PROTOCOL) != V_NONE) { preferredProtocol = optionTemplate->get(PREF_METALINK_PREFERRED_PROTOCOL); } + for(std::vector >::const_iterator i = + entries.begin(), eoi = entries.end(); i != eoi; ++i) { + (*i)->dropUnsupportedResource(); + if((*i)->resources.empty() && (*i)->metaurls.empty()) { + continue; + } + (*i)->setLocationPriority + (locations, -MetalinkResource::getLowestPriority()); + if(!preferredProtocol.empty()) { + (*i)->setProtocolPriority + (preferredProtocol, -MetalinkResource::getLowestPriority()); + } + } std::vector > selectedEntries; - selectedEntries.reserve(entries.size()); - { - int32_t count = 1; - for(std::vector >::const_iterator i = - entries.begin(), eoi = entries.end(); i != eoi; ++i, ++count) { - (*i)->dropUnsupportedResource(); - if((*i)->resources.empty() && (*i)->metaurls.empty()) { - continue; - } - (*i)->setLocationPriority - (locations, -MetalinkResource::getLowestPriority()); - if(!preferredProtocol.empty()) { - (*i)->setProtocolPriority - (preferredProtocol, -MetalinkResource::getLowestPriority()); - } - if(selectIndexes.empty() || - std::binary_search(selectIndexes.begin(), selectIndexes.end(), count)){ - selectedEntries.push_back(*i); + SegList sgl; + util::parseIntSegments(sgl, optionTemplate->get(PREF_SELECT_FILE)); + sgl.normalize(); + if(!sgl.hasNext()) { + selectedEntries.assign(entries.begin(), entries.end()); + } else { + selectedEntries.reserve(entries.size()); + for(size_t i = 0, len = entries.size(); i < len && sgl.hasNext(); ++i) { + size_t j = sgl.peek()-1; + if(i == j) { + selectedEntries.push_back(entries[i]); + sgl.next(); } } }