A little optimization for get_widget_index() in configurator.
authorAndriy Grytsenko <andrej@rep.kiev.ua>
Wed, 20 Aug 2014 12:17:57 +0000 (15:17 +0300)
committerAndriy Grytsenko <andrej@rep.kiev.ua>
Wed, 20 Aug 2014 12:17:57 +0000 (15:17 +0300)
src/configurator.c

index 85acbaa..020e8d4 100644 (file)
@@ -812,12 +812,29 @@ static void modify_plugin( GtkTreeView* view )
     }
 }
 
+typedef struct
+{
+    GtkWidget *pl;
+    int cur;
+    int idx;
+} WidgetIndexData;
+
+static void get_widget_index_cb(GtkWidget *widget, gpointer data)
+{
+    if (((WidgetIndexData *)data)->pl == widget)
+        ((WidgetIndexData *)data)->idx = ((WidgetIndexData *)data)->cur;
+    ((WidgetIndexData *)data)->cur++;
+}
+
 static int get_widget_index(LXPanel* p, GtkWidget* pl)
 {
-    GList *plugins = gtk_container_get_children(GTK_CONTAINER(p->priv->box));
-    int i = g_list_index(plugins, pl);
-    g_list_free(plugins);
-    return i;
+    WidgetIndexData data;
+
+    data.pl = pl;
+    data.idx = -1;
+    data.cur = 0;
+    gtk_container_foreach(GTK_CONTAINER(p->priv->box), get_widget_index_cb, &data);
+    return data.idx;
 }
 
 static void on_moveup_plugin(  GtkButton* btn, GtkTreeView* view )