changeset 2291:0d350e979bde

Don't rebuild the buddylist multiple times before a screen refresh
author franky
date Tue, 01 Nov 2016 08:39:07 +0100
parents 71ec41732035
children f181418db215
files mcabber/mcabber/commands.c mcabber/mcabber/hooks.c mcabber/mcabber/roster.c mcabber/mcabber/roster.h mcabber/mcabber/screen.c mcabber/mcabber/xmpp.c mcabber/mcabber/xmpp_iq.c mcabber/mcabber/xmpp_iqrequest.c
diffstat 8 files changed, 38 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/mcabber/mcabber/commands.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/commands.c	Tue Nov 01 08:39:07 2016 +0100
@@ -602,7 +602,7 @@
       lock = !(buddy_getflags(bud) & ROSTER_FLAG_USRLOCK);
     buddy_setflags(bud, ROSTER_FLAG_USRLOCK, lock);
     if (may_need_refresh) {
-      buddylist_build();
+      buddylist_defer_build();
       update_roster = TRUE;
     }
   }
@@ -833,15 +833,15 @@
   } else if (!strcasecmp(subcmd, "hide_offline")) {
     buddylist_set_hide_offline_buddies(TRUE);
     if (current_buddy)
-      buddylist_build();
+      buddylist_defer_build();
     update_roster = TRUE;
   } else if (!strcasecmp(subcmd, "show_offline")) {
     buddylist_set_hide_offline_buddies(FALSE);
-    buddylist_build();
+    buddylist_defer_build();
     update_roster = TRUE;
   } else if (!strcasecmp(subcmd, "toggle_offline")) {
     buddylist_set_hide_offline_buddies(-1);
-    buddylist_build();
+    buddylist_defer_build();
     update_roster = TRUE;
   } else if (!strcasecmp(subcmd, "display")) {
     scr_roster_display(arg);
@@ -1257,7 +1257,7 @@
 
   buddy_hide_group(group, group_state);
 
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
 
 do_group_return:
@@ -2627,7 +2627,7 @@
   g_free(roomname_tmp);
   g_free(nick);
   g_free(pass_utf8);
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
   free_arg_lst(paramlst);
 }
@@ -2926,7 +2926,7 @@
   // Delete the room
   roster_del_user(buddy_getjid(bud));
   scr_update_buddy_window();
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
 }
 
--- a/mcabber/mcabber/hooks.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/hooks.c	Tue Nov 01 08:39:07 2016 +0100
@@ -567,7 +567,7 @@
 
   roster_setstatus(bjid, rn, prio, status, status_msg, timestamp,
                    role_none, affil_none, NULL);
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
   hlog_write_status(bjid, timestamp, status, status_msg);
 
--- a/mcabber/mcabber/roster.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/roster.c	Tue Nov 01 08:39:07 2016 +0100
@@ -121,6 +121,7 @@
 static GSList *unread_list;
 static GHashTable *unread_jids;
 GList *buddylist;
+static gboolean _rebuild_buddylist = FALSE;
 GList *current_buddy;
 GList *alternate_buddy;
 GList *last_activity_buddy;
@@ -472,7 +473,7 @@
 
   // We need to rebuild the list
   if (current_buddy)
-    buddylist_build();
+    buddylist_defer_build();
   // TODO What we could do, too, is to check if the deleted node is
   // current_buddy, in which case we could move current_buddy to the
   // previous (or next) node.
@@ -518,7 +519,7 @@
     groups = NULL;
     // Update (i.e. free) buddylist
     if (buddylist)
-      buddylist_build();
+      buddylist_defer_build();
   }
 }
 
@@ -718,7 +719,7 @@
   }
 
   if (buddylist && (new_roster_item || !g_list_find(buddylist, roster_usr)))
-    buddylist_build();
+    buddylist_defer_build();
 
 roster_msg_setflag_return:
   if (unread_list_modified) {
@@ -949,6 +950,11 @@
   return display_filter;
 }
 
+void buddylist_defer_build(void)
+{
+  _rebuild_buddylist = TRUE;
+}
+
 //  buddylist_build()
 // Creates the buddylist from the roster entries.
 void buddylist_build(void)
@@ -960,6 +966,10 @@
   roster *roster_last_activity_buddy = NULL;
   int shrunk_group;
 
+  if (_rebuild_buddylist == FALSE)
+    return;
+  _rebuild_buddylist = FALSE;
+
   // We need to remember which buddy is selected.
   if (current_buddy)
     roster_current_buddy = BUDDATA(current_buddy);
@@ -1094,7 +1104,7 @@
   my_newgroup->list = g_slist_insert_sorted(my_newgroup->list, roster_usr,
                                             (GCompareFunc)&roster_compare_name);
 
-  buddylist_build();
+  buddylist_defer_build();
 }
 
 void buddy_setname(gpointer rosterdata, char *newname)
@@ -1118,7 +1128,7 @@
   sl_group = &((roster*)((GSList*)roster_usr->list)->data)->list;
   *sl_group = g_slist_sort(*sl_group, (GCompareFunc)&roster_compare_name);
 
-  buddylist_build();
+  buddylist_defer_build();
 }
 
 const char *buddy_getname(gpointer rosterdata)
@@ -1552,6 +1562,7 @@
   GList *buddy;
   roster *roster_usr;
 
+  buddylist_build();
   if (!buddylist) return NULL;
 
   for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) {
@@ -1570,6 +1581,7 @@
 {
   GList *buddy = current_buddy;
   roster *roster_usr;
+  buddylist_build();
   if (!buddylist || !current_buddy) return NULL;
   for (;;) {
     gchar *jid_locale, *name_locale;
--- a/mcabber/mcabber/roster.h	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/roster.h	Tue Nov 01 08:39:07 2016 +0100
@@ -190,6 +190,7 @@
 guint   roster_getsubscription(const char *jid);
 void    roster_unsubscribed(const char *jid);
 
+void    buddylist_defer_build(void);
 void    buddylist_build(void);
 void    buddy_hide_group(gpointer rosterdata, int hide);
 void    buddylist_set_hide_offline_buddies(int hide);
--- a/mcabber/mcabber/screen.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/screen.c	Tue Nov 01 08:39:07 2016 +0100
@@ -1795,7 +1795,7 @@
 
     // Build the buddylist at least once, to make sure the special buffer
     // is added
-    buddylist_build();
+    buddylist_defer_build();
 
     // Init prev_chatwidth; this variable will be used to prevent us
     // from rewrapping buffers when the width doesn't change.
@@ -2088,6 +2088,8 @@
   // We can reset update_roster
   update_roster = FALSE;
 
+  buddylist_build();
+
   getmaxyx(rosterWnd, maxy, maxx);
   maxx--;  // Last char is for vertical border
 
@@ -2538,7 +2540,7 @@
   }
   // We should rebuild the buddylist but not everytime
   if (!(buddylist_get_filter() & 1<<prev_st))
-    buddylist_build();
+    buddylist_defer_build();
   update_roster = TRUE;
 }
 
@@ -2662,7 +2664,7 @@
                                  sub_none, -1);
   // Set a lock to see it in the buddylist
   buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE);
-  buddylist_build();
+  buddylist_defer_build();
   // Jump to the buddy
   set_current_buddy(buddy_search_jid(barejid));
   if (chatmode) {
@@ -2699,7 +2701,7 @@
     ngroup = buddy_getgroup(unread_ptr);
     if (buddy_getflags(ngroup) & ROSTER_FLAG_HIDE) {
       buddy_setflags(ngroup, ROSTER_FLAG_HIDE, FALSE);
-      buddylist_build();
+      buddylist_defer_build();
     }
   }
 
@@ -2776,7 +2778,7 @@
       if (strchr(filter, imstatus2char[budstate]) || show_all)
         status |= 1<<budstate;
     buddylist_set_filter(status);
-    buddylist_build();
+    buddylist_defer_build();
     update_roster = TRUE;
     return;
   }
--- a/mcabber/mcabber/xmpp.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/xmpp.c	Tue Nov 01 08:39:07 2016 +0100
@@ -142,7 +142,7 @@
 
   roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending, -1);
   g_free(cleanjid);
-  buddylist_build();
+  buddylist_defer_build();
 
   update_roster = TRUE;
 }
@@ -229,7 +229,7 @@
 
   roster_del_user(cleanjid);
   g_free(cleanjid);
-  buddylist_build();
+  buddylist_defer_build();
 
   update_roster = TRUE;
 }
@@ -986,7 +986,7 @@
       buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
     }
 
-    buddylist_build();
+    buddylist_defer_build();
     scr_draw_roster();
     goto gotmessage_return;
   }
--- a/mcabber/mcabber/xmpp_iq.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/xmpp_iq.c	Tue Nov 01 08:39:07 2016 +0100
@@ -668,7 +668,7 @@
     lm_message_unref(result);
   }
 
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
   if (need_refresh)
     scr_update_buddy_window();
--- a/mcabber/mcabber/xmpp_iqrequest.c	Wed Dec 21 20:43:58 2016 +0100
+++ b/mcabber/mcabber/xmpp_iqrequest.c	Tue Nov 01 08:39:07 2016 +0100
@@ -670,7 +670,7 @@
   }
   g_free(bjid);
 
-  buddylist_build();
+  buddylist_defer_build();
   update_roster = TRUE;
 }