Do not traverse the lists returned by filelist_filter() while
allocating new list links with g_list_prepend(). Instead prepend the
lists to dw->add_files_queue using g_list_concat(). Although
g_list_concat() has to traverse the lists containing the new items to
find their ends, it avoids redundant memory allocation and
deallocation.
if (filelist_read(fd, &f, &d))
{
- GList *work;
-
f = filelist_filter(f, FALSE);
d = filelist_filter(d, TRUE);
- work = f;
- while (work)
- {
- dw->add_files_queue = g_list_prepend(dw->add_files_queue, work->data);
- work = work->next;
- }
- g_list_free(f);
- work = d;
- while (work)
- {
- dw->add_files_queue = g_list_prepend(dw->add_files_queue, work->data);
- work = work->next;
- }
- g_list_free(d);
+ dw->add_files_queue = g_list_concat(f, dw->add_files_queue);
+ dw->add_files_queue = g_list_concat(d, dw->add_files_queue);
}
}
else