Bug 1594899 - Remove xpidl [array] use in nsIMsgLocalMailFolder. r=kmelin
authorBen Campbell <benc@thunderbird.net>
Fri, 22 Nov 2019 23:51:25 +0200
changeset 36710 318755e67909cb43c91f2179b258d868c1e1909d
parent 36709 736117fc5641a89df4b114b58def785352607037
child 36711 4c34261831ce476d943f4c25cebdd2aa8101da8c
push id2534
push userclokep@gmail.com
push dateMon, 02 Dec 2019 19:52:51 +0000
treeherdercomm-beta@055c50840778 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskmelin
bugs1594899
Bug 1594899 - Remove xpidl [array] use in nsIMsgLocalMailFolder. r=kmelin
mail/components/extensions/test/browser/head.js
mail/components/extensions/test/xpcshell/head.js
mailnews/local/public/nsIMsgLocalMailFolder.idl
mailnews/local/src/nsLocalMailFolder.cpp
mailnews/test/resources/messageInjection.js
--- a/mail/components/extensions/test/browser/head.js
+++ b/mail/components/extensions/test/browser/head.js
@@ -46,17 +46,17 @@ function addIdentity(account) {
 
 function createMessages(folder, count) {
   const { MessageGenerator } = ChromeUtils.import(
     "resource://testing-common/mailnews/messageGenerator.js"
   );
   let messages = new MessageGenerator().makeMessages({ count });
   let messageStrings = messages.map(message => message.toMboxString());
   folder.QueryInterface(Ci.nsIMsgLocalMailFolder);
-  folder.addMessageBatch(messageStrings.length, messageStrings);
+  folder.addMessageBatch(messageStrings);
 }
 
 async function promiseAnimationFrame(win = window) {
   await new Promise(win.requestAnimationFrame);
   // dispatchToMainThread throws if used as the first argument of Promise.
   return new Promise(resolve => Services.tm.dispatchToMainThread(resolve));
 }
 
--- a/mail/components/extensions/test/xpcshell/head.js
+++ b/mail/components/extensions/test/xpcshell/head.js
@@ -67,11 +67,11 @@ function createMessages(folder, count) {
     "resource://testing-common/mailnews/messageGenerator.js"
   );
   let messages = new MessageGenerator().makeMessages({
     count,
     age_incr: { days: 2 },
   });
   let messageStrings = messages.map(message => message.toMboxString());
   folder.QueryInterface(Ci.nsIMsgLocalMailFolder);
-  folder.addMessageBatch(messageStrings.length, messageStrings);
+  folder.addMessageBatch(messageStrings);
   folder.callFilterPlugins(null);
 }
--- a/mailnews/local/public/nsIMsgLocalMailFolder.idl
+++ b/mailnews/local/public/nsIMsgLocalMailFolder.idl
@@ -79,18 +79,17 @@ interface nsIMsgLocalMailFolder : nsISup
    *
    * Filters are applied, if applicable.
    *
    * @param aMessageCount The number of messages.
    * @param aMessages An array of pointers to strings containing entire message
    *                  bodies.
    * @return an array of nsIMsgDBHdr of the added messages
    */
-  nsIArray addMessageBatch(in uint32_t aMessageCount,
-                           [array, size_is(aMessageCount)] in string aMessages);
+  Array<nsIMsgDBHdr> addMessageBatch(in Array<ACString> aMessages);
 
   /**
    * Functions for updating the UI while running DownloadMessagesForOffline:
    * delete the old message before adding its newly downloaded body, and
    * select the new message after it has replaced the old one
    */
   void deleteDownloadMsg(in nsIMsgDBHdr aMsgHdr, out boolean aDoSelect);
   void selectDownloadMsg();
--- a/mailnews/local/src/nsLocalMailFolder.cpp
+++ b/mailnews/local/src/nsLocalMailFolder.cpp
@@ -3284,17 +3284,17 @@ nsMsgLocalMailFolder::GetUidlFromFolder(
   bool more = false;
   uint32_t size = 0, len = 0;
   const char *accountKey = nullptr;
   nsresult rv = GetMsgInputStream(aMsgDBHdr, &aState->m_streamReusable,
                                   getter_AddRefs(aState->m_inputStream));
   aState->m_seekableStream = do_QueryInterface(aState->m_inputStream);
   NS_ENSURE_SUCCESS(rv, rv);
 
-  nsAutoPtr<nsLineBuffer<char> > lineBuffer(new nsLineBuffer<char>);
+  nsAutoPtr<nsLineBuffer<char>> lineBuffer(new nsLineBuffer<char>);
   NS_ENSURE_TRUE(lineBuffer, NS_ERROR_OUT_OF_MEMORY);
 
   aState->m_uidl = nullptr;
 
   aMsgDBHdr->GetMessageSize(&len);
   while (len > 0) {
     rv = NS_ReadLine(aState->m_inputStream.get(), lineBuffer.get(),
                      aState->m_header, &more);
@@ -3329,31 +3329,31 @@ nsMsgLocalMailFolder::GetUidlFromFolder(
 }
 
 /**
  * Adds a message to the end of the folder, parsing it as it goes, and
  * applying filters, if applicable.
  */
 NS_IMETHODIMP
 nsMsgLocalMailFolder::AddMessage(const char *aMessage, nsIMsgDBHdr **aHdr) {
-  const char *aMessages[] = {aMessage};
-  nsCOMPtr<nsIArray> hdrs;
-  nsresult rv = AddMessageBatch(1, aMessages, getter_AddRefs(hdrs));
+  NS_ENSURE_ARG_POINTER(aHdr);
+  AutoTArray<nsCString, 1> aMessages = {nsDependentCString(aMessage)};
+  nsTArray<RefPtr<nsIMsgDBHdr>> hdrs;
+  nsresult rv = AddMessageBatch(aMessages, hdrs);
   NS_ENSURE_SUCCESS(rv, rv);
-  nsCOMPtr<nsIMsgDBHdr> hdr(do_QueryElementAt(hdrs, 0, &rv));
-  NS_ENSURE_SUCCESS(rv, rv);
-  hdr.forget(aHdr);
+  NS_ADDREF(*aHdr = hdrs[0]);
   return rv;
 }
 
 NS_IMETHODIMP
-nsMsgLocalMailFolder::AddMessageBatch(uint32_t aMessageCount,
-                                      const char **aMessages,
-                                      nsIArray **aHdrArray) {
-  NS_ENSURE_ARG_POINTER(aHdrArray);
+nsMsgLocalMailFolder::AddMessageBatch(
+    const nsTArray<nsCString> &aMessages,
+    nsTArray<RefPtr<nsIMsgDBHdr>> &aHdrArray) {
+  aHdrArray.ClearAndRetainStorage();
+  aHdrArray.SetCapacity(aMessages.Length());
 
   nsCOMPtr<nsIMsgIncomingServer> server;
   nsresult rv = GetServer(getter_AddRefs(server));
   NS_ENSURE_SUCCESS(rv, rv);
 
   nsCOMPtr<nsIMsgPluggableStore> msgStore;
   nsCOMPtr<nsIOutputStream> outFileStream;
   nsCOMPtr<nsIMsgDBHdr> newHdr;
@@ -3368,20 +3368,18 @@ nsMsgLocalMailFolder::AddMessageBatch(ui
   bool isLocked;
 
   GetLocked(&isLocked);
   if (isLocked) return NS_MSG_FOLDER_BUSY;
 
   AcquireSemaphore(static_cast<nsIMsgLocalMailFolder *>(this));
 
   if (NS_SUCCEEDED(rv)) {
-    nsCOMPtr<nsIMutableArray> hdrArray =
-        do_CreateInstance(NS_ARRAY_CONTRACTID, &rv);
     NS_ENSURE_SUCCESS(rv, rv);
-    for (uint32_t i = 0; i < aMessageCount; i++) {
+    for (uint32_t i = 0; i < aMessages.Length(); i++) {
       RefPtr<nsParseNewMailState> newMailParser = new nsParseNewMailState;
       NS_ENSURE_TRUE(newMailParser, NS_ERROR_OUT_OF_MEMORY);
       if (!mGettingNewMessages) newMailParser->DisableFilters();
       bool reusable;
       rv = msgStore->GetNewMsgOutputStream(this, getter_AddRefs(newHdr),
                                            &reusable,
                                            getter_AddRefs(outFileStream));
       NS_ENSURE_SUCCESS(rv, rv);
@@ -3392,28 +3390,28 @@ nsMsgLocalMailFolder::AddMessageBatch(ui
       nsCOMPtr<nsIMsgMailSession> mailSession =
           do_GetService(NS_MSGMAILSESSION_CONTRACTID, &rv);
       if (NS_SUCCEEDED(rv))
         mailSession->GetTopmostMsgWindow(getter_AddRefs(msgWindow));
 
       rv = newMailParser->Init(rootFolder, this, msgWindow, newHdr,
                                outFileStream);
 
-      uint32_t bytesWritten, messageLen = strlen(aMessages[i]);
-      outFileStream->Write(aMessages[i], messageLen, &bytesWritten);
-      newMailParser->BufferInput(aMessages[i], messageLen);
+      uint32_t bytesWritten;
+      uint32_t messageLen = aMessages[i].Length();
+      outFileStream->Write(aMessages[i].get(), messageLen, &bytesWritten);
+      newMailParser->BufferInput(aMessages[i].get(), messageLen);
 
       FinishNewLocalMessage(outFileStream, newHdr, msgStore, newMailParser);
       outFileStream->Close();
       outFileStream = nullptr;
       newMailParser->OnStopRequest(nullptr, NS_OK);
       newMailParser->EndMsgDownload();
-      hdrArray->AppendElement(newHdr);
+      aHdrArray.AppendElement(newHdr);
     }
-    hdrArray.forget(aHdrArray);
   }
   ReleaseSemaphore(static_cast<nsIMsgLocalMailFolder *>(this));
   return rv;
 }
 
 nsresult nsMsgLocalMailFolder::FinishNewLocalMessage(
     nsIOutputStream *aOutputStream, nsIMsgDBHdr *aNewHdr,
     nsIMsgPluggableStore *aMsgStore, nsParseMailMessageState *aParseMsgState) {
--- a/mailnews/test/resources/messageInjection.js
+++ b/mailnews/test/resources/messageInjection.js
@@ -755,17 +755,17 @@ function add_sets_to_folders(aMsgFolders
         continue;
       }
 
       let folder = folderBatch.folder;
       folder.gettingNewMessages = true;
       let messageStrings = folderBatch.messages.map(message =>
         message.synMsg.toMboxString()
       );
-      folder.addMessageBatch(messageStrings.length, messageStrings);
+      folder.addMessageBatch(messageStrings);
 
       for (let message of folderBatch.messages) {
         let synMsgState = message.synMsg.metaState;
         // If we need to mark the message as junk grab the header and do so.
         if (synMsgState.junk) {
           message.messageSet.setJunk(
             true,
             message.messageSet.getMsgHdr(message.index)