Bug 844373 - Clean up _flagNameList iterating in mail/base/content/folderPane.js. r=mkmelin
authoraceman <acelists@atlas.sk>
Wed, 27 Feb 2013 16:45:48 -0500
changeset 15054 bead6b9aeb9fc49894a62bca6cd10e86ea0766dc
parent 15053 0a57d13a21a3afd12ba3f746076c32379ebabc2d
child 15055 a49f5ca048d90166558b45f171b0014f20f7e3cb
push id898
push userbugzilla@standard8.plus.com
push dateMon, 13 May 2013 17:03:31 +0000
treeherdercomm-beta@3106694b14de [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs844373
Bug 844373 - Clean up _flagNameList iterating in mail/base/content/folderPane.js. r=mkmelin
mail/base/content/folderPane.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1404,85 +1404,79 @@ let gFolderTreeView = {
         [nsMsgFolderFlags.Drafts, "Drafts", false, true],
         [nsMsgFolderFlags.SentMail, "Sent", true, true],
         [nsMsgFolderFlags.Trash, "Trash", true, true],
         [nsMsgFolderFlags.Templates, "Templates", false, true],
         [nsMsgFolderFlags.Archive, "Archives", true, true],
         [nsMsgFolderFlags.Junk, "Junk", false, true],
         [nsMsgFolderFlags.Queue, "Outbox", true, true]
       ],
-      // hard code, this could be build from _flagNameList dynamically
-      _smartFlags: nsMsgFolderFlags.Inbox | nsMsgFolderFlags.Drafts |
-                    nsMsgFolderFlags.Trash | nsMsgFolderFlags.SentMail |
-                    nsMsgFolderFlags.Templates |
-                    nsMsgFolderFlags.Junk |
-                    nsMsgFolderFlags.Archive,
 
       /**
        * support for addons to add special folder types, this must be called
        * prior to onload.
-       * 
+       *
        * @param aFolderName  name of the folder
        * @param isDeep  include subfolders
        * @param folderOptions  object with searchStr and searchOnline options, or null
        */
       addSmartFolderType: function ftv_addSmartFolderType(aFolderName, isDeep, isSearchFolder) {
         this._flagNameList.push([0, aFolderName, isDeep, isSearchFolder]);
       },
 
       /**
-       * Returns a triple describing the smart folder if the given folder is a
-       * special folder, else returns null.
+       * Returns an array of 4 elements describing the smart folder
+       * if the given folder is a special folder, else returns null.
        */
       getSmartFolderTypeByName: function ftv_smart__getSmartFolderType(aName) {
-        for each (let [, type,,] in Iterator(this._flagNameList)) {
+        for (let type of this._flagNameList) {
           if (type[1] == aName)
             return type;
         }
         return null;
       },
       /**
        * check to see if a folder is a smart folder
        */
       isSmartFolder: function ftv_smart__isSmartFolder(aFolder) {
-        if (aFolder.flags & this._smartFlags)
+        if (aFolder.flags & this._allSmartFlags)
             return true;
         // Also check the folder name itself, as containers do not
         // have the smartFolderName property.  We check all folders here, since
         // a "real" folder might be marked as a child of a smart folder.
         let smartFolderName = getSmartFolderName(aFolder);
         return smartFolderName && this.getSmartFolderTypeByName(smartFolderName) ||
             this.getSmartFolderTypeByName(aFolder.name);
       },
 
       /**
        * All the flags above, bitwise ORed.
        */
-      get _allFlags() {
-        delete this._allFlags;
-        return this._allFlags = this._flagNameList.reduce(
+      get _allSmartFlags() {
+        delete this._allSmartFlags;
+        return this._allSmartFlags = this._flagNameList.reduce(
           function (res, [flag,, isDeep,]) res | flag, 0);
       },
 
       /**
        * All the "shallow" flags above (isDeep set to false), bitwise ORed.
        */
       get _allShallowFlags() {
         delete this._allShallowFlags;
         return this._allShallowFlags = this._flagNameList.reduce(
           function (res, [flag,, isDeep,]) isDeep ? res : (res | flag), 0);
       },
 
       /**
-       * Returns a triple describing the smart folder if the given folder is a
-       * special folder, else returns null.
+       * Returns an array of 4 elements describing the smart folder
+       * if the given folder is a special folder, else returns null.
        */
       _getSmartFolderType: function ftv_smart__getSmartFolderType(aFolder) {
         let smartFolderName = getSmartFolderName(aFolder);
-        for each (let [, type] in Iterator(this._flagNameList)) {
+        for (let type of this._flagNameList) {
           if (smartFolderName) {
             if (type[1] == smartFolderName)
               return type;
             continue;
           }
           if (aFolder.flags & type[0])
             return type;
         }
@@ -1505,17 +1499,17 @@ let gFolderTreeView = {
         let accounts = gFolderTreeView._sortedAccounts();
         let smartServer = this._smartServer;
         smartServer.prettyName = document.getElementById("bundle_messenger")
                                          .getString("unifiedAccountName");
         smartServer.canHaveFilters = false;
 
         let smartRoot = smartServer.rootFolder;
         let smartChildren = [];
-        for each (let [, [flag, name,,]] in Iterator(this._flagNameList)) {
+        for (let [flag, name,,] of this._flagNameList) {
           gFolderTreeView._addSmartFoldersForFlag(smartChildren, accounts,
                                                   smartRoot, flag, name);
         }
 
         sortFolderItems(smartChildren);
         for each (let smartChild in smartChildren)
           map.push(smartChild);
 
@@ -1543,18 +1537,17 @@ let gFolderTreeView = {
         let smartServer = this._smartServer;
         if (aFolder.server == smartServer)
           // This is a smart mailbox
           return null;
 
         let smartType = this._getSmartFolderType(aFolder);
         if (smartType) {
           // This is a special folder
-          let [, name,] = smartType;
-          let smartFolder = this._getSmartFolderNamed(name);
+          let smartFolder = this._getSmartFolderNamed(smartType[1]);
           if (smartFolder &&
               gFolderTreeView.getIndexOfFolder(smartFolder) != null)
             return smartFolder;
 
           return null;
         }
 
         let parent = aFolder.parent;
@@ -1571,18 +1564,17 @@ let gFolderTreeView = {
        * that type (if it's displayed). Otherwise this returns the folder the
        * message is in.
        */
       getFolderForMsgHdr: function ftv_smart_getFolderForMsgHdr(aMsgHdr) {
         let folder = aMsgHdr.folder;
 
         let smartType = this._getSmartFolderType(folder);
         if (smartType) {
-          let [, name,] = smartType;
-          let smartFolder = this._getSmartFolderNamed(name);
+          let smartFolder = this._getSmartFolderNamed(smartType[1]);
           if (smartFolder &&
               gFolderTreeView.getIndexOfFolder(smartFolder) != null)
             return smartFolder;
         }
         return folder;
       },
 
       /**
@@ -1590,26 +1582,25 @@ let gFolderTreeView = {
        *
        * - If a new special folder is added, we need to add it as a child of the
        *   corresponding smart folder.
        * - If the parent is a shallow special folder, we need to add it as a
        *   top-level folder in its account.
        * - Otherwise, we need to add it as a child of its parent (as normal).
        */
       onFolderAdded: function ftv_smart_onFolderAdded(aParent, aFolder) {
-        if (aFolder.flags & this._allFlags) {
+        if (aFolder.flags & this._allSmartFlags) {
           // add as child of corresponding smart folder
           let smartServer = this._smartServer;
           let smartRoot = smartServer.rootFolder;
           // In theory, a folder can have multiple flags set, so we need to
           // check each flag separately.
-          for each (let [, [flag, name,,]] in Iterator(this._flagNameList)) {
+          for (let [flag, name,,] of this._flagNameList) {
             if (aFolder.flags & flag)
-              gFolderTreeView._addSmartSubFolder(aFolder, smartRoot, name,
-                                                 flag);
+              gFolderTreeView._addSmartSubFolder(aFolder, smartRoot, name, flag);
           }
         }
         else if (aParent.isSpecialFolder(this._allShallowFlags, false)) {
           // add as a child of the account
           let rootIndex = gFolderTreeView.getIndexOfFolder(
             aFolder.server.rootFolder);
           let root = gFolderTreeView._rowMap[rootIndex];
           if (!root)