[gnome-shell] js: Remove unnecessary versions of clutter_actor_get_children



commit c9296191a8bd5631f7e136454708e78202094abb
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue May 29 20:36:45 2012 -0400

    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 9a7258a..c29828b 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 cd6faa1..170df51 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 7929328..82a9552 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 0adf312..962f815 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 d29684f..1e110ca 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 59dc71c..2690f08 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 9efb6f7..873e339 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 86255fa..df5e192 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 6a44a24..f9f3bb8 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 9156849..aecf643 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();
         }
     },



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