[gnome-software] key-colors: Pre-query pixbuf width and height



commit 996007cc0df62cafc2691461787dc85a55c8319b
Author: Philip Withnall <withnall endlessm com>
Date:   Thu Apr 2 13:12:29 2020 +0100

    key-colors: Pre-query pixbuf width and height
    
    Rather than querying them on every loop iteration. In a trace where I
    switched between categories a few times, `gdk_pixbuf_get_width()` was
    being avoidably called 61 million times.
    
    This introduces no functional changes.
    
    Signed-off-by: Philip Withnall <withnall endlessm com>

 plugins/core/gs-plugin-key-colors.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
---
diff --git a/plugins/core/gs-plugin-key-colors.c b/plugins/core/gs-plugin-key-colors.c
index 49efd4a9..c438e811 100644
--- a/plugins/core/gs-plugin-key-colors.c
+++ b/plugins/core/gs-plugin-key-colors.c
@@ -58,7 +58,7 @@ static void
 gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
 {
        gint rowstride, n_channels;
-       gint x, y;
+       gint x, y, width, height;
        guchar *pixels, *p;
        guint bin_size = 200;
        guint i;
@@ -68,12 +68,15 @@ gs_plugin_key_colors_set_for_pixbuf (GsApp *app, GdkPixbuf *pb, guint number)
        n_channels = gdk_pixbuf_get_n_channels (pb);
        rowstride = gdk_pixbuf_get_rowstride (pb);
        pixels = gdk_pixbuf_get_pixels (pb);
+       width = gdk_pixbuf_get_width (pb);
+       height = gdk_pixbuf_get_height (pb);
+
        for (bin_size = 250; bin_size > 0; bin_size -= 2) {
                g_autoptr(GHashTable) hash = NULL;
                hash = g_hash_table_new_full (g_direct_hash,  g_direct_equal,
                                              NULL, g_free);
-               for (y = 0; y < gdk_pixbuf_get_height (pb); y++) {
-                       for (x = 0; x < gdk_pixbuf_get_width (pb); x++) {
+               for (y = 0; y < height; y++) {
+                       for (x = 0; x < width; x++) {
                                CdColorRGB8 tmp;
                                GsColorBin *s;
                                gpointer key;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]