diff --git a/src/download_helper.cc b/src/download_helper.cc index c5773ef4..07776ee3 100644 --- a/src/download_helper.cc +++ b/src/download_helper.cc @@ -189,10 +189,10 @@ createBtRequestGroup(const std::string& torrentFilePath, sgl.normalize(); dctx->setFileFilter(sgl); std::istringstream indexOutIn(option->get(PREF_INDEX_OUT)); - std::map indexPathMap = - util::createIndexPathMap(indexOutIn); - for(std::map::const_iterator i = indexPathMap.begin(), - eoi = indexPathMap.end(); i != eoi; ++i) { + std::vector > indexPaths = + util::createIndexPaths(indexOutIn); + for(std::vector >::const_iterator i = + indexPaths.begin(), eoi = indexPaths.end(); i != eoi; ++i) { dctx->setFilePathWithIndex ((*i).first, util::applyDir(option->get(PREF_DIR), (*i).second)); } diff --git a/src/util.cc b/src/util.cc index 2878aed6..04a65e4b 100644 --- a/src/util.cc +++ b/src/util.cc @@ -1370,7 +1370,7 @@ std::string htmlEscape(const std::string& src) return dest; } -std::map::value_type +std::pair parseIndexPath(const std::string& line) { std::pair p; @@ -1380,17 +1380,17 @@ parseIndexPath(const std::string& line) throw DL_ABORT_EX(fmt("Path with index=%u is empty.", static_cast(index))); } - return std::map::value_type(index, p.second); + return std::make_pair(index, p.second); } -std::map createIndexPathMap(std::istream& i) +std::vector > createIndexPaths(std::istream& i) { - std::map indexPathMap; + std::vector > indexPaths; std::string line; while(getline(i, line)) { - indexPathMap.insert(indexPathMap.begin(), parseIndexPath(line)); + indexPaths.push_back(parseIndexPath(line)); } - return indexPathMap; + return indexPaths; } namespace { diff --git a/src/util.h b/src/util.h index e05d3006..147126d4 100644 --- a/src/util.h +++ b/src/util.h @@ -347,10 +347,10 @@ std::string joinPath(InputIterator first, InputIterator last) // Parses INDEX=PATH format string. INDEX must be an unsigned // integer. -std::map::value_type +std::pair parseIndexPath(const std::string& line); -std::map createIndexPathMap(std::istream& i); +std::vector > createIndexPaths(std::istream& i); /** * Take a string src which is a delimited list and add its elements diff --git a/test/UtilTest.cc b/test/UtilTest.cc index 992bcd41..19acf852 100644 --- a/test/UtilTest.cc +++ b/test/UtilTest.cc @@ -62,7 +62,7 @@ class UtilTest:public CppUnit::TestFixture { CPPUNIT_TEST(testHtmlEscape); CPPUNIT_TEST(testJoinPath); CPPUNIT_TEST(testParseIndexPath); - CPPUNIT_TEST(testCreateIndexPathMap); + CPPUNIT_TEST(testCreateIndexPaths); CPPUNIT_TEST(testGenerateRandomData); CPPUNIT_TEST(testFromHex); CPPUNIT_TEST(testParsePrioritizePieceRange); @@ -122,7 +122,7 @@ public: void testHtmlEscape(); void testJoinPath(); void testParseIndexPath(); - void testCreateIndexPathMap(); + void testCreateIndexPaths(); void testGenerateRandomData(); void testFromHex(); void testParsePrioritizePieceRange(); @@ -1015,7 +1015,7 @@ void UtilTest::testJoinPath() void UtilTest::testParseIndexPath() { - std::map::value_type p = util::parseIndexPath("1=foo"); + std::pair p = util::parseIndexPath("1=foo"); CPPUNIT_ASSERT_EQUAL((size_t)1, p.first); CPPUNIT_ASSERT_EQUAL(std::string("foo"), p.second); try { @@ -1032,17 +1032,17 @@ void UtilTest::testParseIndexPath() } } -void UtilTest::testCreateIndexPathMap() +void UtilTest::testCreateIndexPaths() { std::stringstream in ("1=/tmp/myfile\n" "100=/myhome/mypicture.png\n"); - std::map m = util::createIndexPathMap(in); + std::vector > m = util::createIndexPaths(in); CPPUNIT_ASSERT_EQUAL((size_t)2, m.size()); - CPPUNIT_ASSERT(m.find(1) != m.end()); - CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), m[1]); - CPPUNIT_ASSERT(m.find(100) != m.end()); - CPPUNIT_ASSERT_EQUAL(std::string("/myhome/mypicture.png"), m[100]); + CPPUNIT_ASSERT_EQUAL((size_t)1, m[0].first); + CPPUNIT_ASSERT_EQUAL(std::string("/tmp/myfile"), m[0].second); + CPPUNIT_ASSERT_EQUAL((size_t)100, m[1].first); + CPPUNIT_ASSERT_EQUAL(std::string("/myhome/mypicture.png"), m[1].second); } void UtilTest::testGenerateRandomData()