Skip to content

Commit

Permalink
download_factory: don't check for "removed-right-after-add" when load…
Browse files Browse the repository at this point in the history
…ing session

As no command is attached when loading from session, it is
impossible for this edge case to occur.

"find" on the download list, a "std::list" linked list, is
an O(n) operation. With it, the session loading is O(n^2),
where n is the number of entities in the session directory.

As such, remove this unnecessary check to speed things up.
  • Loading branch information
jesec committed May 13, 2022
1 parent 9eba8ad commit 163fb32
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/core/download_factory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,15 @@ DownloadFactory::receive_success() {
rpc::parse_command_multiple_std(command, rpc::make_target(download));
}

if (m_manager->download_list()->find(infohash) ==
m_manager->download_list()->end())
throw torrent::input_error("The newly created download was removed.");
if (!m_session) {
if (m_manager->download_list()->find(infohash) ==
m_manager->download_list()->end()) {
throw torrent::input_error("The newly created download was removed.");
}

if (!m_session)
rpc::call_command(
"d.state.set", (int64_t)m_start, rpc::make_target(download));
}

rpc::commands.call_catch(m_session ? "event.download.inserted_session"
: "event.download.inserted_new",
Expand Down

0 comments on commit 163fb32

Please sign in to comment.