mirror of
https://github.com/transmission/transmission
synced 2024-12-30 19:46:56 +00:00
refactor: replace tr_list with std::list in sessionLoadTorrents() (#1841)
This commit is contained in:
parent
7f2578008d
commit
78d2074335
1 changed files with 5 additions and 16 deletions
|
@ -13,6 +13,7 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring> /* memcpy */
|
#include <cstring> /* memcpy */
|
||||||
|
#include <list>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
|
@ -2145,10 +2146,6 @@ static void sessionLoadTorrents(void* vdata)
|
||||||
auto* data = static_cast<struct sessionLoadTorrentsData*>(vdata);
|
auto* data = static_cast<struct sessionLoadTorrentsData*>(vdata);
|
||||||
TR_ASSERT(tr_isSession(data->session));
|
TR_ASSERT(tr_isSession(data->session));
|
||||||
|
|
||||||
int i;
|
|
||||||
int n = 0;
|
|
||||||
tr_list* list = nullptr;
|
|
||||||
|
|
||||||
tr_ctorSetSave(data->ctor, false); /* since we already have them */
|
tr_ctorSetSave(data->ctor, false); /* since we already have them */
|
||||||
|
|
||||||
tr_sys_path_info info;
|
tr_sys_path_info info;
|
||||||
|
@ -2157,6 +2154,7 @@ static void sessionLoadTorrents(void* vdata)
|
||||||
tr_sys_dir_open(dirname, nullptr) :
|
tr_sys_dir_open(dirname, nullptr) :
|
||||||
TR_BAD_SYS_DIR;
|
TR_BAD_SYS_DIR;
|
||||||
|
|
||||||
|
auto torrents = std::list<tr_torrent*>{};
|
||||||
if (odir != TR_BAD_SYS_DIR)
|
if (odir != TR_BAD_SYS_DIR)
|
||||||
{
|
{
|
||||||
char const* name;
|
char const* name;
|
||||||
|
@ -2171,8 +2169,7 @@ static void sessionLoadTorrents(void* vdata)
|
||||||
|
|
||||||
if ((tor = tr_torrentNew(data->ctor, nullptr, nullptr)) != nullptr)
|
if ((tor = tr_torrentNew(data->ctor, nullptr, nullptr)) != nullptr)
|
||||||
{
|
{
|
||||||
tr_list_prepend(&list, tor);
|
torrents.push_back(tor);
|
||||||
++n;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tr_free(path);
|
tr_free(path);
|
||||||
|
@ -2182,17 +2179,9 @@ static void sessionLoadTorrents(void* vdata)
|
||||||
tr_sys_dir_close(odir, nullptr);
|
tr_sys_dir_close(odir, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int const n = std::size(torrents);
|
||||||
data->torrents = tr_new(tr_torrent*, n);
|
data->torrents = tr_new(tr_torrent*, n);
|
||||||
i = 0;
|
std::copy(std::begin(torrents), std::end(torrents), data->torrents);
|
||||||
|
|
||||||
for (tr_list* l = list; l != nullptr; l = l->next)
|
|
||||||
{
|
|
||||||
data->torrents[i++] = (tr_torrent*)l->data;
|
|
||||||
}
|
|
||||||
|
|
||||||
TR_ASSERT(i == n);
|
|
||||||
|
|
||||||
tr_list_free(&list, nullptr);
|
|
||||||
|
|
||||||
if (n != 0)
|
if (n != 0)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue