From c9296191a8bd5631f7e136454708e78202094abb Mon Sep 17 00:00:00 2001 From: "Jasper St. Pierre" Date: Tue, 29 May 2012 20:36:45 -0400 Subject: [PATCH] js: Remove unnecessary versions of clutter_actor_get_children clutter_actor_get_children requires making a temporary GSList from a linked list structure, and then creating a JS Array from that GSList. For simple cases like the number of children, use clutter_actor_get_n_children. https://bugzilla.gnome.org/show_bug.cgi?id=677426 --- js/ui/calendar.js | 2 +- js/ui/endSessionDialog.js | 5 ++--- js/ui/iconGrid.js | 10 ++++------ js/ui/lookingGlass.js | 6 +++--- js/ui/messageTray.js | 11 +++++------ js/ui/overview.js | 1 - js/ui/popupMenu.js | 2 +- js/ui/search.js | 2 +- js/ui/shellMountOperation.js | 4 ++-- js/ui/telepathyClient.js | 2 +- 10 files changed, 20 insertions(+), 25 deletions(-) diff --git a/js/ui/calendar.js b/js/ui/calendar.js index 9a7258a2d..c29828b88 100644 --- a/js/ui/calendar.js +++ b/js/ui/calendar.js @@ -448,7 +448,7 @@ const Calendar = new Lang.Class({ } // All the children after this are days, and get removed when we update the calendar - this._firstDayIndex = this.actor.get_children().length; + this._firstDayIndex = this.actor.get_n_children(); }, _onStyleChange: function(actor, event) { diff --git a/js/ui/endSessionDialog.js b/js/ui/endSessionDialog.js index cd6faa17e..170df51f7 100644 --- a/js/ui/endSessionDialog.js +++ b/js/ui/endSessionDialog.js @@ -31,7 +31,6 @@ const St = imports.gi.St; const Shell = imports.gi.Shell; const GnomeSession = imports.misc.gnomeSession; -const Lightbox = imports.ui.lightbox; const Main = imports.ui.main; const ModalDialog = imports.ui.modalDialog; const Tweener = imports.ui.tweener; @@ -288,13 +287,13 @@ const EndSessionDialog = new Lang.Class({ this._applicationList.connect('actor-added', Lang.bind(this, function() { - if (this._applicationList.get_children().length == 1) + if (this._applicationList.get_n_children() == 1) scrollView.show(); })); this._applicationList.connect('actor-removed', Lang.bind(this, function() { - if (this._applicationList.get_children().length == 0) + if (this._applicationList.get_n_children() == 0) scrollView.hide(); })); diff --git a/js/ui/iconGrid.js b/js/ui/iconGrid.js index 792932868..82a9552b8 100644 --- a/js/ui/iconGrid.js +++ b/js/ui/iconGrid.js @@ -309,10 +309,8 @@ const IconGrid = new Lang.Class({ this._grid.queue_relayout(); }, - removeAll: function () { - this._grid.get_children().forEach(Lang.bind(this, function (child) { - child.destroy(); - })); + removeAll: function() { + this._grid.destroy_all_children(); }, addItem: function(actor) { @@ -320,10 +318,10 @@ const IconGrid = new Lang.Class({ }, getItemAtIndex: function(index) { - return this._grid.get_children()[index]; + return this._grid.get_child_at_index(index); }, visibleItemsCount: function() { - return this._grid.get_children().length - this._grid.get_n_skip_paint(); + return this._grid.get_n_children() - this._grid.get_n_skip_paint(); } }); diff --git a/js/ui/lookingGlass.js b/js/ui/lookingGlass.js index 0adf312c3..962f81516 100644 --- a/js/ui/lookingGlass.js +++ b/js/ui/lookingGlass.js @@ -38,7 +38,7 @@ var commandHeader = 'const Clutter = imports.gi.Clutter; ' + 'const stage = global.stage; ' + 'const color = function(pixel) { let c= new Clutter.Color(); c.from_pixel(pixel); return c; }; ' + /* Special lookingGlass functions */ - 'const it = Main.lookingGlass.getIt(); ' + + 'const it = Main.lookingGlass.getIt(); ' + 'const r = Lang.bind(Main.lookingGlass, Main.lookingGlass.getResult); '; const HISTORY_KEY = 'looking-glass-history'; @@ -320,7 +320,7 @@ const WindowList = new Lang.Class({ }, _updateWindowList: function() { - this.actor.get_children().forEach(function (actor) { actor.destroy(); }); + this.actor.destroy_all_children(); let windows = global.get_window_actors(); let tracker = Shell.WindowTracker.get_default(); for (let i = 0; i < windows.length; i++) { @@ -378,7 +378,7 @@ const ObjInspector = new Lang.Class({ this._previousObj = null; this._obj = obj; - this._container.get_children().forEach(function (child) { child.destroy(); }); + this._container.destroy_all_children(); let hbox = new St.BoxLayout({ style_class: 'lg-obj-inspector-title' }); this._container.add_actor(hbox); diff --git a/js/ui/messageTray.js b/js/ui/messageTray.js index d29684f26..1e110ca6c 100644 --- a/js/ui/messageTray.js +++ b/js/ui/messageTray.js @@ -756,7 +756,7 @@ const Notification = new Lang.Class({ button.label = label; } - if (this._buttonBox.get_children().length > 0) + if (this._buttonBox.get_n_children() > 0) this._buttonFocusManager.remove_group(this._buttonBox); this._buttonBox.add(button); @@ -1284,7 +1284,7 @@ const SummaryItem = new Lang.Class({ }, prepareNotificationStackForShowing: function() { - if (this.notificationStack.get_children().length > 0) + if (this.notificationStack.get_n_children() > 0) return; for (let i = 0; i < this.source.notifications.length; i++) { @@ -1293,7 +1293,6 @@ const SummaryItem = new Lang.Class({ }, doneShowingNotificationStack: function() { - let notificationActors = this.notificationStack.get_children(); for (let i = 0; i < this._stackedNotifications.length; i++) { let stackedNotification = this._stackedNotifications[i]; let notification = stackedNotification.notification; @@ -1323,7 +1322,7 @@ const SummaryItem = new Lang.Class({ this._stackedNotifications.push(stackedNotification); if (!this.source.isChat) notification.enableScrolling(false); - if (this.notificationStack.get_children().length > 0) + if (this.notificationStack.get_n_children() > 0) notification.setIconVisible(false); this.notificationStack.add(notification.actor); notification.expand(false); @@ -2436,7 +2435,7 @@ const MessageTray = new Lang.Class({ }, _onSummaryBoxPointerContentUpdated: function() { - if (this._summaryBoxPointerItem.notificationStack.get_children().length == 0) + if (this._summaryBoxPointerItem.notificationStack.get_n_children() == 0) this._hideSummaryBoxPointer(); this._adjustSummaryBoxPointerPosition(); @@ -2470,7 +2469,7 @@ const MessageTray = new Lang.Class({ // We should be sure to hide the box pointer if all notifications in it are destroyed while // it is hiding, so that we don't show an an animation of an empty blob being hidden. if (this._summaryBoxPointerState == State.HIDING && - this._summaryBoxPointerItem.notificationStack.get_children().length == 0) { + this._summaryBoxPointerItem.notificationStack.get_n_children() == 0) { this._summaryBoxPointer.actor.hide(); return; } diff --git a/js/ui/overview.js b/js/ui/overview.js index 59dc71c42..2690f08a4 100644 --- a/js/ui/overview.js +++ b/js/ui/overview.js @@ -14,7 +14,6 @@ const AppDisplay = imports.ui.appDisplay; const ContactDisplay = imports.ui.contactDisplay; const Dash = imports.ui.dash; const DND = imports.ui.dnd; -const Lightbox = imports.ui.lightbox; const Main = imports.ui.main; const MessageTray = imports.ui.messageTray; const Panel = imports.ui.panel; diff --git a/js/ui/popupMenu.js b/js/ui/popupMenu.js index 9efb6f74d..873e3395b 100644 --- a/js/ui/popupMenu.js +++ b/js/ui/popupMenu.js @@ -906,7 +906,7 @@ const PopupMenuBase = new Lang.Class({ }, isEmpty: function() { - return this.box.get_children().length == 0; + return this.box.get_n_children() == 0; }, isChildMenu: function(menu) { diff --git a/js/ui/search.js b/js/ui/search.js index 86255fa1f..df5e192ab 100644 --- a/js/ui/search.js +++ b/js/ui/search.js @@ -51,7 +51,7 @@ const SearchResultDisplay = new Lang.Class({ * Remove all results from this display. */ clear: function() { - this.actor.get_children().forEach(function (actor) { actor.destroy(); }); + this.actor.destroy_all_children(); }, /** diff --git a/js/ui/shellMountOperation.js b/js/ui/shellMountOperation.js index 6a44a247d..f9f3bb899 100644 --- a/js/ui/shellMountOperation.js +++ b/js/ui/shellMountOperation.js @@ -347,13 +347,13 @@ const ShellProcessesDialog = new Lang.Class({ this._applicationList.connect('actor-added', Lang.bind(this, function() { - if (this._applicationList.get_children().length == 1) + if (this._applicationList.get_n_children() == 1) scrollView.show(); })); this._applicationList.connect('actor-removed', Lang.bind(this, function() { - if (this._applicationList.get_children().length == 0) + if (this._applicationList.get_n_children() == 0) scrollView.hide(); })); }, diff --git a/js/ui/telepathyClient.js b/js/ui/telepathyClient.js index 91568495a..aecf64370 100644 --- a/js/ui/telepathyClient.js +++ b/js/ui/telepathyClient.js @@ -802,7 +802,7 @@ const ChatNotification = new Lang.Class({ let groups = this._contentArea.get_children(); for (let i = 0; i < groups.length; i++) { let group = groups[i]; - if (group.get_children().length == 0) + if (group.get_n_children() == 0) group.destroy(); } },