Bug 1612237 - Remove nsIArray use from nsIMsgFilter interface. r=mkmelin
authorBen Campbell <benc@thunderbird.net>
Thu, 30 Jan 2020 13:00:05 +1300
changeset 37320 596c14b1987917d23d6817d06c21350b37018d63
parent 37319 f25bd8743ae1edfa3b2cb4c4d169c671a686bcd5
child 37321 251268cf2381022d14714028b5d30afcaeaa7a2a
push id2566
push userclokep@gmail.com
push dateMon, 09 Mar 2020 19:20:31 +0000
treeherdercomm-beta@a352facfa0a4 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1612237
Bug 1612237 - Remove nsIArray use from nsIMsgFilter interface. r=mkmelin
mailnews/base/search/content/FilterEditor.js
mailnews/base/search/public/nsIMsgFilter.idl
mailnews/base/search/src/nsMsgFilter.cpp
mailnews/base/search/src/nsMsgFilter.h
mailnews/base/search/src/nsMsgFilterService.cpp
mailnews/imap/src/nsImapMailFolder.cpp
mailnews/local/src/nsParseMailbox.cpp
mailnews/news/src/nsNNTPNewsgroupList.cpp
--- a/mailnews/base/search/content/FilterEditor.js
+++ b/mailnews/base/search/content/FilterEditor.js
@@ -618,22 +618,17 @@ function _checkActionsReorder() {
   }
 
   // Now get the actions out of the filter in the order they will be executed in.
   gActionListOrdered = gTempFilter.sortedActionList;
 
   // Compare the two lists.
   let statusBar = document.getElementById("statusbar");
   for (let index = 0; index < gActionListOrdered.length; index++) {
-    if (
-      index !=
-      gTempFilter.getActionIndex(
-        gActionListOrdered.queryElementAt(index, nsIMsgRuleAction)
-      )
-    ) {
+    if (index != gTempFilter.getActionIndex(gActionListOrdered[index])) {
       // If the lists are not the same unhide the status bar and show warning.
       statusBar.style.visibility = "visible";
       return;
     }
   }
 
   statusBar.style.visibility = "hidden";
 }
@@ -665,19 +660,17 @@ function showActionsOrder() {
       }
     }
     actionStrings.push(actionString);
   }
 
   // Present a nicely formatted list of action names and arguments.
   let actionList = gFilterBundle.getString("filterActionOrderExplanation");
   for (let i = 0; i < gActionListOrdered.length; i++) {
-    let actionIndex = gTempFilter.getActionIndex(
-      gActionListOrdered.queryElementAt(i, nsIMsgRuleAction)
-    );
+    let actionIndex = gTempFilter.getActionIndex(gActionListOrdered[i]);
     let action = actionStrings[actionIndex];
     actionList += gFilterBundle.getFormattedString("filterActionItem", [
       i + 1,
       action.label,
       action.argument,
     ]);
   }
 
--- a/mailnews/base/search/public/nsIMsgFilter.idl
+++ b/mailnews/base/search/public/nsIMsgFilter.idl
@@ -118,12 +118,12 @@ interface nsIMsgFilter : nsISupports {
 
     void appendAction(in nsIMsgRuleAction action);
 
     readonly attribute unsigned long actionCount;
 
     void clearActionList();
 
     // Returns the action list in the order it will be really executed in.
-    readonly attribute nsIArray sortedActionList;
+    readonly attribute Array<nsIMsgRuleAction> sortedActionList;
 
     void SaveToTextFile(in nsIOutputStream aStream);
 };
--- a/mailnews/base/search/src/nsMsgFilter.cpp
+++ b/mailnews/base/search/src/nsMsgFilter.cpp
@@ -250,85 +250,71 @@ nsMsgFilter::CreateAction(nsIMsgRuleActi
 //   index    action(s)
 //  -------   ---------
 //     0      FetchBodyFromPop3Server
 //    1..n    all other 'normal' actions, in their original order
 //  n+1..m    CopyToFolder
 //    m+1     MoveToFolder or Delete
 //    m+2     StopExecution
 NS_IMETHODIMP
-nsMsgFilter::GetSortedActionList(nsIArray **aActionList) {
-  NS_ENSURE_ARG_POINTER(aActionList);
-
-  uint32_t numActions;
-  nsresult rv = GetActionCount(&numActions);
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIMutableArray> orderedActions(
-      do_CreateInstance(NS_ARRAY_CONTRACTID, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
+nsMsgFilter::GetSortedActionList(
+    nsTArray<RefPtr<nsIMsgRuleAction>> &aActionList) {
+  aActionList.Clear();
+  aActionList.SetCapacity(m_actionList.Length());
 
   // hold separate pointers into the action list
   uint32_t nextIndexForNormal = 0, nextIndexForCopy = 0, nextIndexForMove = 0;
-  for (uint32_t index = 0; index < numActions; ++index) {
-    nsCOMPtr<nsIMsgRuleAction> action;
-    rv = GetActionAt(index, getter_AddRefs(action));
-    if (NS_FAILED(rv) || !action) continue;
+  for (auto action : m_actionList) {
+    if (!action) continue;
 
     nsMsgRuleActionType actionType;
     action->GetType(&actionType);
     switch (actionType) {
       case nsMsgFilterAction::FetchBodyFromPop3Server: {
         // always insert in front
-        rv = orderedActions->InsertElementAt(action, 0);
-        NS_ENSURE_SUCCESS(rv, rv);
+        aActionList.InsertElementAt(0, action);
         ++nextIndexForNormal;
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::CopyToFolder: {
         // insert into copy actions block, in order of appearance
-        rv = orderedActions->InsertElementAt(action, nextIndexForCopy);
-        NS_ENSURE_SUCCESS(rv, rv);
+        aActionList.InsertElementAt(nextIndexForCopy, action);
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::MoveToFolder:
       case nsMsgFilterAction::Delete: {
         // insert into move/delete action block
-        rv = orderedActions->InsertElementAt(action, nextIndexForMove);
-        NS_ENSURE_SUCCESS(rv, rv);
+        aActionList.InsertElementAt(nextIndexForMove, action);
         ++nextIndexForMove;
         break;
       }
 
       case nsMsgFilterAction::StopExecution: {
         // insert into stop action block
-        rv = orderedActions->AppendElement(action);
-        NS_ENSURE_SUCCESS(rv, rv);
+        aActionList.AppendElement(action);
         break;
       }
 
       default: {
         // insert into normal action block, in order of appearance
-        rv = orderedActions->InsertElementAt(action, nextIndexForNormal);
-        NS_ENSURE_SUCCESS(rv, rv);
+        aActionList.InsertElementAt(nextIndexForNormal, action);
         ++nextIndexForNormal;
         ++nextIndexForCopy;
         ++nextIndexForMove;
         break;
       }
     }
   }
 
-  orderedActions.forget(aActionList);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsMsgFilter::AppendAction(nsIMsgRuleAction *aAction) {
   NS_ENSURE_ARG_POINTER(aAction);
 
   m_actionList.AppendElement(aAction);
--- a/mailnews/base/search/src/nsMsgFilter.h
+++ b/mailnews/base/search/src/nsMsgFilter.h
@@ -91,13 +91,13 @@ class nsMsgFilter : public nsIMsgFilter 
   bool m_enabled;
   bool m_temporary;
   bool m_unparseable;
   nsIMsgFilterList *m_filterList;       /* owning filter list */
   nsCOMPtr<nsIMutableArray> m_termList; /* linked list of criteria terms */
   nsCOMPtr<nsIMsgSearchScopeTerm>
       m_scope; /* default for mail rules is inbox, but news rules could
               have a newsgroup - LDAP would be invalid */
-  nsTArray<nsCOMPtr<nsIMsgRuleAction> > m_actionList;
+  nsTArray<nsCOMPtr<nsIMsgRuleAction>> m_actionList;
   nsMsgSearchBoolExpression *m_expressionTree;
 };
 
 #endif
--- a/mailnews/base/search/src/nsMsgFilterService.cpp
+++ b/mailnews/base/search/src/nsMsgFilterService.cpp
@@ -648,22 +648,21 @@ nsresult nsMsgFilterAfterTheFact::ApplyF
       break;  // Maybe not an error, we just need to call AdvanceToNextFolder();
 
     BREAK_IF_FALSE(m_searchHitHdrs, "No search headers object");
     // we're going to log the filter actions before firing them because some
     // actions are async
     bool loggingEnabled = false;
     if (m_filters) (void)m_filters->GetLoggingEnabled(&loggingEnabled);
 
-    nsCOMPtr<nsIArray> actionList;
-    rv = m_curFilter->GetSortedActionList(getter_AddRefs(actionList));
+    nsTArray<RefPtr<nsIMsgRuleAction>> actionList;
+    rv = m_curFilter->GetSortedActionList(actionList);
     BREAK_IF_FAILURE(rv, "Could not get action list for filter");
 
-    uint32_t numActions;
-    actionList->GetLength(&numActions);
+    uint32_t numActions = actionList.Length();
 
     if (m_nextAction == 0) {
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
               ("(Post) Applying %" PRIu32 " filter actions to %" PRIu32
                " matched messages",
                numActions, static_cast<uint32_t>(m_searchHits.Length())));
     } else if (m_nextAction < numActions) {
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
@@ -672,19 +671,18 @@ nsresult nsMsgFilterAfterTheFact::ApplyF
                numActions - m_nextAction,
                static_cast<uint32_t>(m_searchHits.Length())));
     }
 
     // We start from m_nextAction to allow us to continue applying actions
     // after the return from an async copy.
     while (m_nextAction < numActions) {
       nsresult finalResult = NS_OK;
-      nsCOMPtr<nsIMsgRuleAction> filterAction(
-          do_QueryElementAt(actionList, m_nextAction++, &rv));
-      CONTINUE_IF_FAILURE(rv, "actionList cannot QI element");
+      nsCOMPtr<nsIMsgRuleAction> filterAction(actionList[m_nextAction]);
+      ++m_nextAction;
 
       nsMsgRuleActionType actionType;
       rv = filterAction->GetType(&actionType);
       CONTINUE_IF_FAILURE(rv, "Could not get type for filter action");
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
               ("(Post) Running filter action at index %" PRIu32
                ", action type = %i",
                m_nextAction - 1, actionType));
--- a/mailnews/imap/src/nsImapMailFolder.cpp
+++ b/mailnews/imap/src/nsImapMailFolder.cpp
@@ -3147,23 +3147,21 @@ NS_IMETHODIMP nsImapMailFolder::ApplyFil
     GetMessageHeader(m_curMsgUid, getter_AddRefs(msgHdr));
   else if (m_msgParser)
     m_msgParser->GetNewMsgHdr(getter_AddRefs(msgHdr));
   NS_ENSURE_TRUE(msgHdr,
                  NS_ERROR_NULL_POINTER);  // fatal error, cannot apply filters
 
   bool deleteToTrash = DeleteIsMoveToTrash();
 
-  nsCOMPtr<nsIArray> filterActionList;
-  rv = filter->GetSortedActionList(getter_AddRefs(filterActionList));
+  nsTArray<RefPtr<nsIMsgRuleAction>> filterActionList;
+  rv = filter->GetSortedActionList(filterActionList);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  uint32_t numActions;
-  rv = filterActionList->GetLength(&numActions);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t numActions = filterActionList.Length();
 
   nsCString msgId;
   msgHdr->GetMessageId(getter_Copies(msgId));
   nsMsgKey msgKey;
   msgHdr->GetMessageKey(&msgKey);
   MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
           ("(Imap) Applying %" PRIu32
            " filter actions on message with key %" PRIu32,
@@ -3177,19 +3175,18 @@ NS_IMETHODIMP nsImapMailFolder::ApplyFil
 
   bool msgIsNew = true;
 
   rv = GetDatabase();
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsresult finalResult = NS_OK;  // result of all actions
   for (uint32_t actionIndex = 0; actionIndex < numActions; actionIndex++) {
-    nsCOMPtr<nsIMsgRuleAction> filterAction =
-        do_QueryElementAt(filterActionList, actionIndex, &rv);
-    if (NS_FAILED(rv) || !filterAction) {
+    nsCOMPtr<nsIMsgRuleAction> filterAction(filterActionList[actionIndex]);
+    if (!filterAction) {
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Warning,
               ("(Imap) Filter action at index %" PRIu32 " invalid, skipping",
                actionIndex));
       continue;
     }
 
     rv = NS_OK;  // result of the current action
     nsMsgRuleActionType actionType;
--- a/mailnews/local/src/nsParseMailbox.cpp
+++ b/mailnews/local/src/nsParseMailbox.cpp
@@ -1829,23 +1829,21 @@ NS_IMETHODIMP nsParseNewMailState::Apply
 
   uint32_t newFlags;
   nsresult rv = NS_OK;
 
   *applyMore = true;
 
   nsCOMPtr<nsIMsgDBHdr> msgHdr = m_newMsgHdr;
 
-  nsCOMPtr<nsIArray> filterActionList;
-  rv = filter->GetSortedActionList(getter_AddRefs(filterActionList));
+  nsTArray<RefPtr<nsIMsgRuleAction>> filterActionList;
+  rv = filter->GetSortedActionList(filterActionList);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  uint32_t numActions;
-  rv = filterActionList->GetLength(&numActions);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t numActions = filterActionList.Length();
 
   nsCString msgId;
   msgHdr->GetMessageId(getter_Copies(msgId));
   nsMsgKey msgKey;
   msgHdr->GetMessageKey(&msgKey);
   MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
           ("(Local) Applying %" PRIu32
            " filter actions on message with key %" PRIu32,
@@ -1856,19 +1854,18 @@ NS_IMETHODIMP nsParseNewMailState::Apply
   bool loggingEnabled = false;
   if (m_filterList && numActions)
     m_filterList->GetLoggingEnabled(&loggingEnabled);
 
   bool msgIsNew = true;
   nsresult finalResult = NS_OK;  // result of all actions
   for (uint32_t actionIndex = 0; actionIndex < numActions && *applyMore;
        actionIndex++) {
-    nsCOMPtr<nsIMsgRuleAction> filterAction =
-        do_QueryElementAt(filterActionList, actionIndex, &rv);
-    if (NS_FAILED(rv) || !filterAction) {
+    nsCOMPtr<nsIMsgRuleAction> filterAction(filterActionList[actionIndex]);
+    if (!filterAction) {
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Warning,
               ("(Local) Filter action at index %" PRIu32 " invalid, skipping",
                actionIndex));
       continue;
     }
 
     nsMsgRuleActionType actionType;
     if (NS_SUCCEEDED(filterAction->GetType(&actionType))) {
--- a/mailnews/news/src/nsNNTPNewsgroupList.cpp
+++ b/mailnews/news/src/nsNNTPNewsgroupList.cpp
@@ -566,23 +566,21 @@ NS_IMETHODIMP nsNNTPNewsgroupList::Apply
   NS_ENSURE_ARG_POINTER(aFilter);
   NS_ENSURE_ARG_POINTER(aApplyMore);
   NS_ENSURE_TRUE(m_newMsgHdr, NS_ERROR_UNEXPECTED);
   NS_ENSURE_TRUE(m_newsDB, NS_ERROR_UNEXPECTED);
 
   // you can't move news messages, so applyMore is always true
   *aApplyMore = true;
 
-  nsCOMPtr<nsIArray> filterActionList;
-  nsresult rv = aFilter->GetSortedActionList(getter_AddRefs(filterActionList));
+  nsTArray<RefPtr<nsIMsgRuleAction>> filterActionList;
+  nsresult rv = aFilter->GetSortedActionList(filterActionList);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  uint32_t numActions;
-  rv = filterActionList->GetLength(&numActions);
-  NS_ENSURE_SUCCESS(rv, rv);
+  uint32_t numActions = filterActionList.Length();
 
   nsCString msgId;
   m_newMsgHdr->GetMessageId(getter_Copies(msgId));
   nsMsgKey msgKey;
   m_newMsgHdr->GetMessageKey(&msgKey);
   MOZ_LOG(FILTERLOGMODULE, LogLevel::Info,
           ("(News) Applying filter actions on message with key %" PRIu32,
            msgKeyToInt(msgKey)));
@@ -592,19 +590,18 @@ NS_IMETHODIMP nsNNTPNewsgroupList::Apply
   bool loggingEnabled = false;
   nsCOMPtr<nsIMsgFilterList> currentFilterList;
   rv = aFilter->GetFilterList(getter_AddRefs(currentFilterList));
   if (NS_SUCCEEDED(rv) && currentFilterList && numActions)
     currentFilterList->GetLoggingEnabled(&loggingEnabled);
 
   nsresult finalResult = NS_OK;  // result of all actions
   for (uint32_t actionIndex = 0; actionIndex < numActions; actionIndex++) {
-    nsCOMPtr<nsIMsgRuleAction> filterAction =
-        do_QueryElementAt(filterActionList, actionIndex, &rv);
-    if (NS_FAILED(rv) || !filterAction) {
+    nsCOMPtr<nsIMsgRuleAction> filterAction(filterActionList[actionIndex]);
+    if (!filterAction) {
       MOZ_LOG(FILTERLOGMODULE, LogLevel::Warning,
               ("(News) Filter action at index %" PRIu32 " invalid, skipping",
                actionIndex));
       continue;
     }
 
     nsMsgRuleActionType actionType;
     if (NS_SUCCEEDED(filterAction->GetType(&actionType))) {