remove unique.count(url) (#1964)

This commit is contained in:
Pavel Pimenov 2017-05-04 03:18:30 +03:00 committed by Arvid Norberg
parent 4530f56616
commit 0ac16532ee
2 changed files with 27 additions and 5 deletions

View File

@ -1475,8 +1475,7 @@ namespace libtorrent {
web_seed_entry ent(maybe_url_encode(url.string_value().to_string())
, web_seed_entry::url_seed);
if ((m_flags & multifile) && ent.url[ent.url.size() - 1] != '/') ent.url += '/';
if (unique.count(ent.url)) continue;
unique.insert(ent.url);
if (!unique.insert(ent.url).second) continue;
m_web_seeds.push_back(ent);
}
}
@ -1497,9 +1496,8 @@ namespace libtorrent {
{
bdecode_node const url = http_seeds.list_at(i);
if (url.type() != bdecode_node::string_t || url.string_length() == 0) continue;
std::string u = maybe_url_encode(url.string_value().to_string());
if (unique.count(u)) continue;
unique.insert(u);
std::string const u = maybe_url_encode(url.string_value().to_string());
if (!unique.insert(u).second) continue;
m_web_seeds.push_back(web_seed_entry(u, web_seed_entry::http_seed));
}
}

View File

@ -178,6 +178,30 @@ test_failing_torrent_t test_error_torrents[] =
// TODO: torrent_info constructor that takes an invalid bencoded buffer
// TODO: verify_encoding with a string that triggers character replacement
TORRENT_TEST(url_list_and_httpseeds)
{
entry info;
info["pieces"] = "aaaaaaaaaaaaaaaaaaaa";
info["name.utf-8"] = "test1";
info["name"] = "test__";
info["piece length"] = 16 * 1024;
info["length"] = 3245;
entry::list_type l;
l.push_back(entry("http://foo.com/bar1"));
l.push_back(entry("http://foo.com/bar1"));
l.push_back(entry("http://foo.com/bar2"));
entry const e(l);
entry torrent;
torrent["url-list"] = e;
torrent["httpseeds"] = e;
torrent["info"] = info;
std::vector<char> buf;
bencode(std::back_inserter(buf), torrent);
error_code ec;
torrent_info ti(&buf[0], int(buf.size()), ec);
TEST_EQUAL(ti.web_seeds().size(), 4);
}
TORRENT_TEST(add_url_seed)
{
torrent_info ti(sha1_hash(" "));