dupe: Avoid O(n) operations in dupe_files_add_queue_cb()
authorFrej Drejhammar <frej.drejhammar@gmail.com>
Sat, 13 Feb 2021 15:54:24 +0000 (16:54 +0100)
committerFrej Drejhammar <frej.drejhammar@gmail.com>
Sat, 27 Mar 2021 11:49:19 +0000 (12:49 +0100)
Replace tests that use g_list_length(), which traverses the list with
simple constant-time NULL checks. That an empty list is NULL is
documented in the GList documentation.

src/dupe.c

index 09dd34b..75e27ab 100644 (file)
@@ -2353,7 +2353,7 @@ static gboolean dupe_files_add_queue_cb(gpointer data)
 
        gtk_progress_bar_pulse(GTK_PROGRESS_BAR(dw->extra_label));
 
-       if (g_list_length(queue) == 0)
+       if (queue == NULL)
                {
                dw->add_files_queue_id = 0;
                g_idle_add(dupe_check_start_cb, dw);
@@ -2456,7 +2456,7 @@ static gboolean dupe_files_add_queue_cb(gpointer data)
                dw->list = g_list_prepend(dw->list, di);
                }
 
-       if (g_list_length(dw->add_files_queue) > 0)
+       if (dw->add_files_queue != NULL)
                {
                return TRUE;
                }