From 31f67d914294cda360c472babfc48bda74220338 Mon Sep 17 00:00:00 2001 From: Giovanni Campagna Date: Sun, 12 May 2013 20:13:43 +0200 Subject: [PATCH] MessageTray: don't list the sources all the time The point of a hash table is that you don't need to list all the elements. To avoid that, keep a "clearableCount" in MessageTray, which can be used by the message tray menu to show and hide the clear item, and that is updated in constant time when sources are added or removed. https://bugzilla.gnome.org/show_bug.cgi?id=700194 --- js/ui/messageTray.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index 665d980c6..7349961ae 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -1530,11 +1530,7 @@ const MessageTrayContextMenu = new Lang.Class({ }, _updateClearSensitivity: function() { - let sources = this._tray.getSources(); - sources = sources.filter(function(source) { - return !source.trayIcon && !source.isChat && !source.resident; - }); - this._clearItem.setSensitive(sources.length > 0); + this._clearItem.setSensitive(this._tray.clearableCount > 0); }, setPosition: function(x, y) { @@ -1661,6 +1657,8 @@ const MessageTray = new Lang.Class({ this._desktopClone = null; this._inCtrlAltTab = false; + this.clearableCount = 0; + this._lightbox = new Lightbox.Lightbox(global.overlay_group, { inhibitEvents: true, fadeInTime: ANIMATION_TIME, @@ -1899,6 +1897,9 @@ const MessageTray = new Lang.Class({ this._summary.insert_child_at_index(summaryItem.actor, this._chatSummaryItemsCount); } + if (!source.trayIcon && !source.isChat && !source.resident) + this.clearableCount++; + this._sources.set(source, obj); obj.notifyId = source.connect('notify', Lang.bind(this, this._onNotify)); @@ -1940,6 +1941,9 @@ const MessageTray = new Lang.Class({ if (source.isChat) this._chatSummaryItemsCount--; + if (!source.trayIcon && !source.isChat && !source.resident) + this.clearableCount--; + source.disconnect(obj.notifyId); source.disconnect(obj.destroyId); source.disconnect(obj.mutedChangedId);