Bug 955366 - Use Maps and Sets in IRC code, convert setModes. r=aleth
authorPatrick Cloke <clokep@gmail.com>
Mon, 19 May 2014 13:19:56 -0400
changeset 16208 3cb370e6812d4a42337f53d55be8f10ec82b6930
parent 16207 9001c159773fb2ee682287bb70db0472aaafade9
child 16209 8200f186be4653d8762fd056f548c1bf6b8110e1
push id10134
push userclokep@gmail.com
push dateMon, 19 May 2014 17:20:23 +0000
treeherdercomm-central@3cb370e6812d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaleth
bugs955366
Bug 955366 - Use Maps and Sets in IRC code, convert setModes. r=aleth
chat/protocols/irc/irc.js
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -412,31 +412,31 @@ ircChannel.prototype = {
     if (aNewMode[0] != "+" && aNewMode[0] != "-") {
       this.WARN("Invalid mode string: " + aNewMode);
       return;
     }
     let addNewMode = aNewMode[0] == "+";
 
     // Check each mode being added and update the user.
     let channelModes = [];
-    let userModes = {};
+    let userModes = new NormalizedMap(this.normalizeNick.bind(this));
     let msg;
 
     for (let i = aNewMode.length - 1; i > 0; --i) {
       // Since some modes are conflicted between different server
       // implementations, check if a participant with that name exists. If this
       // is true, then update the mode of the ConvChatBuddy.
       if (this._account.memberStatuses.indexOf(aNewMode[i]) != -1 &&
           aModeParams.length && this._participants.has(peekNextParam())) {
         // Store the new modes for this nick (so each participant's mode is only
         // updated once).
-        let nick = this.normalizeNick(getNextParam());
-        if (!hasOwnProperty(userModes, nick))
-          userModes[nick] = [];
-        userModes[nick].push(aNewMode[i]);
+        let nick = getNextParam();
+        if (!userModes.has(nick))
+          userModes.set(nick, []);
+        userModes.get(nick).push(aNewMode[i]);
 
         // Don't use this mode as a channel mode.
         continue;
       }
       else if (aNewMode[i] == "k") {
         // Channel key.
         let newFields = this.name;
         if (addNewMode) {
@@ -489,18 +489,18 @@ ircChannel.prototype = {
       // Keep track of the channel modes in the order they were received.
       channelModes.unshift(aNewMode[i]);
     }
 
     if (aModeParams.length)
       this.WARN("Unused mode parameters: " + aModeParams.join(", "));
 
     // Update the mode of each participant.
-    for (let nick in userModes)
-      this.getParticipant(nick).setMode(addNewMode, userModes[nick], aSetter);
+    for (let [nick, mode] of userModes.entries())
+      this.getParticipant(nick).setMode(addNewMode, mode, aSetter);
 
     if (!channelModes.length)
       return;
 
     // Store the channel modes.
     _setMode.call(this, addNewMode, channelModes);
 
     // Notify the UI of changes.