Bug 1612239 - Remove redundant nsIMsgFolder.ListDescendants(). r=mkmelin DONTBUILD
authorBen Campbell <benc@thunderbird.net>
Mon, 01 Jun 2020 13:59:00 +0300
changeset 39304 e16540d657cc413bc89d47f3aec912ca380dbfd2
parent 39303 61ac6bd1437164bdf56c15b96cd14080f078da73
child 39305 7add3004e469cb6bc40dc8f18691f71910367ed8
push id402
push userclokep@gmail.com
push dateMon, 29 Jun 2020 20:48:04 +0000
reviewersmkmelin
bugs1612239
Bug 1612239 - Remove redundant nsIMsgFolder.ListDescendants(). r=mkmelin DONTBUILD
mail/base/modules/MailUtils.jsm
mail/components/im/IMIncomingServer.jsm
mailnews/base/public/nsIMsgFolder.idl
mailnews/base/src/nsMsgAccountManager.cpp
mailnews/base/util/nsMsgDBFolder.cpp
mailnews/extensions/newsblog/content/FeedUtils.jsm
--- a/mail/base/modules/MailUtils.jsm
+++ b/mail/base/modules/MailUtils.jsm
@@ -1,17 +1,14 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 var EXPORTED_SYMBOLS = ["MailUtils"];
 
-const { fixIterator, toXPCOMArray } = ChromeUtils.import(
-  "resource:///modules/iteratorUtils.jsm"
-);
 const { MailConsts } = ChromeUtils.import("resource:///modules/MailConsts.jsm");
 const { MailServices } = ChromeUtils.import(
   "resource:///modules/MailServices.jsm"
 );
 const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
 const { PluralForm } = ChromeUtils.import(
   "resource://gre/modules/PluralForm.jsm"
 );
@@ -360,24 +357,22 @@ var MailUtils = {
    *     problem.
    */
   setStringPropertyOnFolderAndDescendents(
     aPropertyName,
     aPropertyValue,
     aFolder,
     aCallback
   ) {
-    // We need to add the base folder as it does not get added by ListDescendants.
-    let allFolders = toXPCOMArray([aFolder], Ci.nsIMutableArray);
-    // - get all the descendants
-    aFolder.ListDescendants(allFolders);
+    // We need to add the base folder as it is not included by .descendants.
+    let allFolders = [aFolder, ...aFolder.descendants];
 
     // - worker function
     function* folder_string_setter_worker() {
-      for (let folder of fixIterator(allFolders, Ci.nsIMsgFolder)) {
+      for (let folder of allFolders) {
         // set the property; this may open the database...
         let value =
           typeof aPropertyValue == "function"
             ? aPropertyValue(folder)
             : aPropertyValue;
         folder.setStringProperty(aPropertyName, value);
         // force the reference to be forgotten.
         folder.msgDatabase = null;
--- a/mail/components/im/IMIncomingServer.jsm
+++ b/mail/components/im/IMIncomingServer.jsm
@@ -316,17 +316,16 @@ IMIncomingServer.prototype = {
       }, // never displayed?
       // used in the folder pane tree, if we don't hide the IM accounts:
       get abbreviatedName() {
         return this.server.prettyName + "abbreviatedName";
       },
       AddFolderListener() {},
       RemoveFolderListener() {},
       descendants: [],
-      ListDescendants(descendants) {},
       getFlag: () => false,
       getFolderWithFlags: aFlags => null,
       getFoldersWithFlags: aFlags =>
         Cc["@mozilla.org/array;1"].createInstance(Ci.nsIArray),
       get subFolders() {
         return EmptyEnumerator;
       },
       getStringProperty: aPropertyName => "",
--- a/mailnews/base/public/nsIMsgFolder.idl
+++ b/mailnews/base/public/nsIMsgFolder.idl
@@ -735,23 +735,16 @@ interface nsIMsgFolder : nsISupports {
 
   void NotifyItemAdded(in nsISupports item);
   void NotifyItemRemoved(in nsISupports item);
 
   void NotifyFolderEvent(in ACString event);
 
   // Gets all descendants, not just first level children.
   readonly attribute Array<nsIMsgFolder> descendants;
-  /*
-   * Lists all the folders that are subfolders of the current folder,
-   * all levels of children.
-   *
-   * @param aDescendants  The array in which to append the found folder(s).
-   */
-  void ListDescendants(in nsIMutableArray aDescendants);
   void Shutdown(in boolean shutdownChildren);
 
   void copyDataToOutputStreamForAppend(in nsIInputStream aIStream,
                      in long aLength, in nsIOutputStream outputStream);
   void copyDataDone();
   void setJunkScoreForMessages(in nsIArray aMessages, in ACString aJunkScore);
   void applyRetentionSettings();
 
--- a/mailnews/base/src/nsMsgAccountManager.cpp
+++ b/mailnews/base/src/nsMsgAccountManager.cpp
@@ -2883,34 +2883,27 @@ nsresult nsMsgAccountManager::RemoveVFLi
 
 NS_IMETHODIMP nsMsgAccountManager::GetAllFolders(
     nsTArray<RefPtr<nsIMsgFolder>> &aAllFolders) {
   aAllFolders.Clear();
   nsTArray<RefPtr<nsIMsgIncomingServer>> allServers;
   nsresult rv = GetAllServers(allServers);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsCOMPtr<nsIMutableArray> allFolders(
-      do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-
   for (auto server : allServers) {
     if (server) {
       nsCOMPtr<nsIMsgFolder> rootFolder;
       server->GetRootFolder(getter_AddRefs(rootFolder));
-      if (rootFolder) rootFolder->ListDescendants(allFolders);
+      if (rootFolder) {
+        nsTArray<RefPtr<nsIMsgFolder>> descendents;
+        rootFolder->GetDescendants(descendents);
+        aAllFolders.AppendElements(descendents);
+      }
     }
   }
-
-  uint32_t length;
-  allFolders->GetLength(&length);
-  for (uint32_t i = 0; i < length; ++i) {
-    nsCOMPtr<nsIMsgFolder> folder = do_QueryElementAt(allFolders, i);
-    aAllFolders.AppendElement(folder);
-  }
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgAccountManager::OnItemAdded(nsIMsgFolder *parentItem,
                                                nsISupports *item) {
   nsCOMPtr<nsIMsgFolder> folder = do_QueryInterface(item);
   // just kick out with a success code if the item in question is not a folder
   if (!folder) return NS_OK;
--- a/mailnews/base/util/nsMsgDBFolder.cpp
+++ b/mailnews/base/util/nsMsgDBFolder.cpp
@@ -4637,42 +4637,28 @@ NS_IMETHODIMP nsMsgDBFolder::GetMessageH
   NS_ENSURE_ARG_POINTER(aMsgHdr);
   nsCOMPtr<nsIMsgDatabase> database;
   nsresult rv = GetMsgDatabase(getter_AddRefs(database));
   NS_ENSURE_SUCCESS(rv, rv);
   return (database) ? database->GetMsgHdrForKey(msgKey, aMsgHdr)
                     : NS_ERROR_FAILURE;
 }
 
-NS_IMETHODIMP nsMsgDBFolder::GetDescendants(nsTArray<RefPtr<nsIMsgFolder>> &aDescendants) {
+NS_IMETHODIMP nsMsgDBFolder::GetDescendants(
+    nsTArray<RefPtr<nsIMsgFolder>> &aDescendants) {
   aDescendants.Clear();
   for (nsIMsgFolder *child : mSubFolders) {
     aDescendants.AppendElement(child);
     nsTArray<RefPtr<nsIMsgFolder>> grandchildren;
     child->GetDescendants(grandchildren);
     aDescendants.AppendElements(grandchildren);
   }
   return NS_OK;
 }
 
-// this gets the deep sub-folders too, e.g., the children of the children
-NS_IMETHODIMP nsMsgDBFolder::ListDescendants(nsIMutableArray *aDescendants) {
-  NS_ENSURE_ARG_POINTER(aDescendants);
-
-  nsCOMPtr<nsISimpleEnumerator> dummy;
-  GetSubFolders(getter_AddRefs(dummy));  // initialize mSubFolders
-  uint32_t count = mSubFolders.Count();
-  for (uint32_t i = 0; i < count; i++) {
-    nsCOMPtr<nsIMsgFolder> child(mSubFolders[i]);
-    aDescendants->AppendElement(child);
-    child->ListDescendants(aDescendants);  // recurse
-  }
-  return NS_OK;
-}
-
 NS_IMETHODIMP nsMsgDBFolder::GetBaseMessageURI(nsACString &baseMessageURI) {
   if (mBaseMessageURI.IsEmpty()) return NS_ERROR_FAILURE;
   baseMessageURI = mBaseMessageURI;
   return NS_OK;
 }
 
 NS_IMETHODIMP nsMsgDBFolder::GetUriForMsg(nsIMsgDBHdr *msgHdr,
                                           nsACString &aURI) {
--- a/mailnews/extensions/newsblog/content/FeedUtils.jsm
+++ b/mailnews/extensions/newsblog/content/FeedUtils.jsm
@@ -281,38 +281,33 @@ var FeedUtils = {
       // according to its own lastUpdatTime/update frequency.
       if (FeedUtils.getStatus(aFolder, aFolder.URI).lastUpdateTime === null) {
         inStartup = true;
       }
 
       FeedUtils.setStatus(aFolder, aFolder.URI, "lastUpdateTime", Date.now());
     }
 
-    let allFolders = Cc["@mozilla.org/array;1"].createInstance(
-      Ci.nsIMutableArray
-    );
+    let allFolders = aFolder.descendants;
     if (!aFolder.isServer) {
-      // Add the base folder; it does not get returned by ListDescendants. Do not
+      // Add the base folder; it does not get returned by .descendants. Do not
       // add the account folder as it doesn't have the feedUrl property or even
       // a msgDatabase necessarily.
-      allFolders.appendElement(aFolder);
+      allFolders.unshift(aFolder);
     }
 
-    aFolder.ListDescendants(allFolders);
-
     let folder;
     function* feeder() {
-      let numFolders = allFolders.length;
-      for (let i = 0; i < numFolders; i++) {
-        folder = allFolders.queryElementAt(i, Ci.nsIMsgFolder);
+      for (let i = 0; i < allFolders.length; i++) {
+        folder = allFolders[i];
         FeedUtils.log.debug(
           "downloadFeed: START x/# folderName:folderPath - " +
             (i + 1) +
             "/" +
-            numFolders +
+            allFolders.length +
             " " +
             folder.name +
             " : " +
             folder.filePath.path
         );
 
         let feedUrlArray = FeedUtils.getFeedUrlsInFolder(folder);
         // Continue if there are no feedUrls for the folder in the feeds
@@ -1073,22 +1068,17 @@ var FeedUtils = {
         ? aOrigFolder.parent.URI
         : aOrigFolder.rootFolder.URI;
     }
 
     this.updateFolderChangeInFeedsDS(newFolder, aOrigFolder, null, null);
 
     // There may be subfolders, but we only get a single notification; iterate
     // over all descendent folders of the folder whose location has changed.
-    let newSubFolders = Cc["@mozilla.org/array;1"].createInstance(
-      Ci.nsIMutableArray
-    );
-    newFolder.ListDescendants(newSubFolders);
-    for (let i = 0; i < newSubFolders.length; i++) {
-      let newSubFolder = newSubFolders.queryElementAt(i, Ci.nsIMsgFolder);
+    for (let newSubFolder of newFolder.descendants) {
       FeedUtils.updateFolderChangeInFeedsDS(
         newSubFolder,
         aOrigFolder,
         newParentURI,
         origParentURI
       );
     }
   },