refactor: replace tr_torrentFiles() with tr_torrentFileProgress() (#1994)

* refactor: s/tr_torrentFiles/tr_torrentFileProgress

Replace tr_torrentFiles() with a new function, tr_torrentFileProgress().

tr_torrentFiles() heap-allocated an array of progress structs. There is
nothing intrinsic in tr_torrent making batch computation more efficient,
so this PR replaces it with tr_torrentFileProgress(), a per-file variant
that doesn't use the heap.
This commit is contained in:
Charles Kerr
2021-10-21 13:31:03 -05:00
committed by GitHub
parent b0fd4b474a
commit 8cdc2c633e
8 changed files with 32 additions and 103 deletions

View File

@@ -384,38 +384,28 @@ static void addLabels(tr_torrent const* tor, tr_variant* list)
static void addFileStats(tr_torrent const* tor, tr_variant* list)
{
auto n = tr_file_index_t{};
auto* files = tr_torrentFiles(tor, &n);
auto const* const info = tr_torrentInfo(tor);
for (tr_file_index_t i = 0; i < info->fileCount; ++i)
{
tr_file const* file = &info->files[i];
tr_variant* d = tr_variantListAddDict(list, 3);
tr_variantDictAddInt(d, TR_KEY_bytesCompleted, files[i].bytesCompleted);
auto const* const file = &info->files[i];
tr_variant* const d = tr_variantListAddDict(list, 3);
tr_variantDictAddInt(d, TR_KEY_bytesCompleted, tr_torrentFileProgress(tor, i).bytes_completed);
tr_variantDictAddInt(d, TR_KEY_priority, file->priority);
tr_variantDictAddBool(d, TR_KEY_wanted, !file->dnd);
}
tr_torrentFilesFree(files, n);
}
static void addFiles(tr_torrent const* tor, tr_variant* list)
{
auto n = tr_file_index_t{};
auto* const files = tr_torrentFiles(tor, &n);
auto const* const info = tr_torrentInfo(tor);
for (tr_file_index_t i = 0; i < info->fileCount; ++i)
{
tr_file const* file = &info->files[i];
tr_variant* d = tr_variantListAddDict(list, 3);
tr_variantDictAddInt(d, TR_KEY_bytesCompleted, files[i].bytesCompleted);
tr_variantDictAddInt(d, TR_KEY_bytesCompleted, tr_torrentFileProgress(tor, i).bytes_completed);
tr_variantDictAddInt(d, TR_KEY_length, file->length);
tr_variantDictAddStr(d, TR_KEY_name, file->name);
}
tr_torrentFilesFree(files, n);
}
static void addWebseeds(tr_info const* info, tr_variant* webseeds)