Bug 1363445: Speed up MessageChannel.addListener. r=aswan
authorKris Maglione <maglione.k@gmail.com>
Tue, 09 May 2017 10:22:41 -0700
changeset 357440 151d199e0b37642c1adeecb768fff3543dfd05bb
parent 357439 3be9f4acec69b52aa0e34a949bfa1f938ed2d1e2
child 357441 2713f06c0631f0e8696bdbc37a013f68c2ff29a3
push id31792
push usercbook@mozilla.com
push dateWed, 10 May 2017 13:07:59 +0000
treeherdermozilla-central@ebbcdaa5b580 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaswan
bugs1363445
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1363445: Speed up MessageChannel.addListener. r=aswan MozReview-Commit-ID: iYavkWIQC
toolkit/components/extensions/MessageChannel.jsm
--- a/toolkit/components/extensions/MessageChannel.jsm
+++ b/toolkit/components/extensions/MessageChannel.jsm
@@ -453,33 +453,39 @@ this.MessageChannel = {
    *        matches this filter, as determined by `matchesFilter` with
    *        `strict=false`.
    *
    *      filterMessage:
    *        An optional function that prevents the handler from handling a
    *        message by returning `false`. See `getHandlers` for the parameters.
    */
   addListener(targets, messageName, handler) {
-    for (let target of [].concat(targets)) {
+    if (!Array.isArray(targets)) {
+      targets = [targets];
+    }
+    for (let target of targets) {
       this.messageManagers.get(target).addHandler(messageName, handler);
     }
   },
 
   /**
    * Removes a message listener from the given message manager.
    *
    * @param {nsIMessageListenerManager|Array<nsIMessageListenerManager>} targets
    *    The message managers on which to stop listening.
    * @param {string|number} messageName
    *    The name of the message to stop listening for.
    * @param {MessageReceiver} handler
    *    The handler to stop dispatching to.
    */
   removeListener(targets, messageName, handler) {
-    for (let target of [].concat(targets)) {
+    if (!Array.isArray(targets)) {
+      targets = [targets];
+    }
+    for (let target of targets) {
       if (this.messageManagers.has(target)) {
         this.messageManagers.get(target).removeHandler(messageName, handler);
       }
     }
   },
 
   /**
    * Sends a message via the given message manager. Returns a promise which