diff options
author | Přemysl Eric Janouch <p@janouch.name> | 2021-11-12 12:20:39 +0100 |
---|---|---|
committer | Přemysl Eric Janouch <p@janouch.name> | 2021-11-12 12:22:36 +0100 |
commit | 3299cbf8254a8bc5a39f48836d8d4dc1b3eaab87 (patch) | |
tree | f96fd4e3840a9f738f6607ab29653e0cbba55910 | |
parent | 972bd80fa5a3964c59f1bc9fb2938ee6a662c76f (diff) | |
download | fiv-3299cbf8254a8bc5a39f48836d8d4dc1b3eaab87.tar.gz fiv-3299cbf8254a8bc5a39f48836d8d4dc1b3eaab87.tar.xz fiv-3299cbf8254a8bc5a39f48836d8d4dc1b3eaab87.zip |
Parallelize thumbnail loading
GLib makes this easy.
They should all be local, and fast to access, so the CPU is the limit.
-rw-r--r-- | fastiv-browser.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/fastiv-browser.c b/fastiv-browser.c index e4ffa4e..385096f 100644 --- a/fastiv-browser.c +++ b/fastiv-browser.c @@ -561,6 +561,14 @@ rescale_thumbnail(cairo_surface_t *thumbnail) return scaled; } +static void +entry_add_thumbnail(gpointer data, G_GNUC_UNUSED gpointer user_data) +{ + Entry *self = data; + self->thumbnail = + rescale_thumbnail(fastiv_io_lookup_thumbnail(self->filename)); +} + void fastiv_browser_load(FastivBrowser *self, const char *path) { @@ -577,15 +585,17 @@ fastiv_browser_load(FastivBrowser *self, const char *path) continue; gchar *subpath = g_build_filename(path, filename, NULL); - g_array_append_val(self->entries, - ((Entry){ - .thumbnail = - rescale_thumbnail(fastiv_io_lookup_thumbnail(subpath)), - .filename = subpath, - })); + g_array_append_val( + self->entries, ((Entry) {.thumbnail = NULL, .filename = subpath})); } g_dir_close(dir); + GThreadPool *pool = g_thread_pool_new( + entry_add_thumbnail, NULL, g_get_num_processors(), FALSE, NULL); + for (guint i = 0; i < self->entries->len; i++) + g_thread_pool_push(pool, &g_array_index(self->entries, Entry, i), NULL); + g_thread_pool_free(pool, FALSE, TRUE); + // TODO(p): Sort the entries. gtk_widget_queue_resize(GTK_WIDGET(self)); } |