Bug 633131 - Remove nsVoidArray from nsMsgCopyService; r=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Thu, 10 Feb 2011 20:45:15 +0000
changeset 7122 f8a93b79758c506404bd4ccad0d5018240b62f83
parent 7121 e52dcdd14f7b614cd0d1af1a09f96e9acc08097f
child 7123 9db390d87be41096d2c8b884c21e837ddb0f367d
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs633131
Bug 633131 - Remove nsVoidArray from nsMsgCopyService; r=bienvenu
mailnews/base/src/nsMsgCopyService.cpp
mailnews/base/src/nsMsgCopyService.h
--- a/mailnews/base/src/nsMsgCopyService.cpp
+++ b/mailnews/base/src/nsMsgCopyService.cpp
@@ -86,25 +86,19 @@ nsCopyRequest::nsCopyRequest() :
 {
   MOZ_COUNT_CTOR(nsCopyRequest);
 }
 
 nsCopyRequest::~nsCopyRequest()
 {
   MOZ_COUNT_DTOR(nsCopyRequest);
 
-  PRInt32 j;
-  nsCopySource* ncs;
-
-  j = m_copySourceArray.Count();
+  PRInt32 j = m_copySourceArray.Length();
   while(j-- > 0)
-  {
-      ncs = (nsCopySource*) m_copySourceArray.ElementAt(j);
-      delete ncs;
-  }
+    delete m_copySourceArray.ElementAt(j);
 }
 
 nsresult
 nsCopyRequest::Init(nsCopyRequestType type, nsISupports* aSupport,
                     nsIMsgFolder* dstFolder,
                     PRBool bVal, PRUint32 newMsgFlags, 
                     const nsACString &newMsgKeywords,
                     nsIMsgCopyServiceListener* listener,
@@ -144,44 +138,37 @@ nsCopyRequest::Init(nsCopyRequestType ty
 }
 
 nsCopySource*
 nsCopyRequest::AddNewCopySource(nsIMsgFolder* srcFolder)
 {
   nsCopySource* newSrc = new nsCopySource(srcFolder);
   if (newSrc)
   {
-      m_copySourceArray.AppendElement((void*) newSrc);
+      m_copySourceArray.AppendElement(newSrc);
       if (srcFolder == m_dstFolder)
         newSrc->m_processed = PR_TRUE;
   }
   return newSrc;
 }
 
 // ************* nsMsgCopyService ****************
 //
 
 
 nsMsgCopyService::nsMsgCopyService()
 {
 }
 
 nsMsgCopyService::~nsMsgCopyService()
 {
-
-  PRInt32 i;
-  nsCopyRequest* copyRequest;
-
-  i = m_copyRequests.Count();
+  PRInt32 i = m_copyRequests.Length();
 
-  while(i-- > 0)
-  {
-      copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
-      ClearRequest(copyRequest, NS_ERROR_FAILURE);
-  }
+  while (i-- > 0)
+    ClearRequest(m_copyRequests.ElementAt(i), NS_ERROR_FAILURE);
 }
 
 
 nsresult
 nsMsgCopyService::ClearRequest(nsCopyRequest* aRequest, nsresult rv)
 {
   if (aRequest)
   {
@@ -193,28 +180,29 @@ nsMsgCopyService::ClearRequest(nsCopyReq
       {
         PRBool hasListeners;
         notifier->GetHasListeners(&hasListeners);
         if (hasListeners)
         {
           // Iterate over the copy sources and append their message arrays to this mutable array
           // or in the case of folders, the source folder.
           PRInt32 cnt, i;
-          cnt = aRequest->m_copySourceArray.Count();
+          cnt = aRequest->m_copySourceArray.Length();
           for (i = 0; i < cnt; i++)
           {
-            nsCopySource *copySource = (nsCopySource*) aRequest->m_copySourceArray.ElementAt(i);
+            nsCopySource *copySource = aRequest->m_copySourceArray.ElementAt(i);
             notifier->NotifyFolderMoveCopyCompleted(aRequest->m_isMoveOrDraftOrTemplate, copySource->m_msgFolder, aRequest->m_dstFolder);
           }
         }
       }
     }
 
     // undo stuff
-    if (aRequest->m_allowUndo && aRequest->m_copySourceArray.Count() > 1 &&
+    if (aRequest->m_allowUndo &&
+        aRequest->m_copySourceArray.Length() > 1 &&
         aRequest->m_txnMgr)
         aRequest->m_txnMgr->EndBatch();
 
     m_copyRequests.RemoveElement(aRequest);
     if (aRequest->m_listener)
         aRequest->m_listener->OnStopCopy(rv);
     delete aRequest;
   }
@@ -225,21 +213,20 @@ nsMsgCopyService::ClearRequest(nsCopyReq
 nsresult
 nsMsgCopyService::QueueRequest(nsCopyRequest* aRequest, PRBool *aCopyImmediately)
 {
   NS_ENSURE_ARG_POINTER(aRequest);
   NS_ENSURE_ARG_POINTER(aCopyImmediately);
   *aCopyImmediately = PR_TRUE;
   nsCopyRequest* copyRequest;
 
-  PRInt32 cnt, i;
-  cnt = m_copyRequests.Count();
-  for (i=0; i < cnt; i++)
+  PRUint32 cnt = m_copyRequests.Length();
+  for (PRUint32 i = 0; i < cnt; i++)
   {
-    copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
+    copyRequest = m_copyRequests.ElementAt(i);
     if (aRequest->m_requestType == nsCopyFoldersType)
     {
       // For copy folder, see if both destination folder (root)
       // (ie, Local Folder) and folder name (ie, abc) are the same.
       if (copyRequest->m_dstFolderName == aRequest->m_dstFolderName &&
           copyRequest->m_dstFolder.get() == aRequest->m_dstFolder.get())
       {
         *aCopyImmediately = PR_FALSE;
@@ -256,55 +243,56 @@ nsMsgCopyService::QueueRequest(nsCopyReq
 }
 
 nsresult
 nsMsgCopyService::DoCopy(nsCopyRequest* aRequest)
 {
   NS_ENSURE_ARG(aRequest);
   PRBool copyImmediately;
   QueueRequest(aRequest, &copyImmediately);
-  m_copyRequests.AppendElement((void*) aRequest);
+  m_copyRequests.AppendElement(aRequest);
   if (copyImmediately) // if there wasn't another request for this dest folder then we can copy immediately
     return DoNextCopy();
 
   return NS_OK;
 }
 
 nsresult
 nsMsgCopyService::DoNextCopy()
 {
   nsresult rv = NS_OK;
   nsCopyRequest* copyRequest = nsnull;
   nsCopySource* copySource = nsnull;
-  PRInt32 i, j, cnt, scnt;
+  PRUint32 i, j, scnt;
 
-  cnt = m_copyRequests.Count();
+  PRUint32 cnt = m_copyRequests.Length();
   if (cnt > 0)
   {
     nsCOMArray<nsIMsgFolder> activeTargets;
 
     // ** jt -- always FIFO
-    for (i=0; i < cnt; i++)
+    for (i = 0; i < cnt; i++)
     {
-      copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
+      copyRequest = m_copyRequests.ElementAt(i);
       copySource = nsnull;
-      scnt = copyRequest->m_copySourceArray.Count();
+      scnt = copyRequest->m_copySourceArray.Length();
       if (!copyRequest->m_processed)
       {
         // if the target folder of this request already has an active
         // copy request, skip this request for now.
         if (activeTargets.IndexOfObject(copyRequest->m_dstFolder) != kNotFound)
         {
           copyRequest = nsnull;
           continue;
         }
-        if (scnt <= 0) goto found; // must be CopyFileMessage
-        for (j=0; j < scnt; j++)
+        if (scnt <= 0)
+            goto found; // must be CopyFileMessage
+        for (j = 0; j < scnt; j++)
         {
-          copySource = (nsCopySource*) copyRequest->m_copySourceArray.ElementAt(j);
+          copySource = copyRequest->m_copySourceArray.ElementAt(j);
           if (!copySource->m_processed)
             goto found;
         }
         if (j >= scnt) // all processed set the value
           copyRequest->m_processed = PR_TRUE;
       }
       if (copyRequest->m_processed) // keep track of folders actively getting copied to.
         activeTargets.AppendObject(copyRequest->m_dstFolder);
@@ -375,22 +363,20 @@ nsMsgCopyService::DoNextCopy()
  * @param aSupport the iSupports of the source folder.
  * @param dstFolder the destination folder of the copy request.
  */
 nsCopyRequest*
 nsMsgCopyService::FindRequest(nsISupports* aSupport,
                               nsIMsgFolder* dstFolder)
 {
   nsCopyRequest* copyRequest = nsnull;
-  PRInt32 cnt, i;
-
-  cnt = m_copyRequests.Count();
-  for (i = 0; i < cnt; i++)
+  PRUint32 cnt = m_copyRequests.Length();
+  for (PRUint32 i = 0; i < cnt; i++)
   {
-    copyRequest = (nsCopyRequest*) m_copyRequests.ElementAt(i);
+    copyRequest = m_copyRequests.ElementAt(i);
     if (copyRequest->m_requestType == nsCopyFoldersType)
     {
         // If the src is different then check next request.
         if (copyRequest->m_srcSupport.get() != aSupport)
         {
           copyRequest = nsnull;
           continue;
         }
@@ -517,17 +503,17 @@ nsMsgCopyService::CopyMessages(nsIMsgFol
       cnt = msgArray.Count();
       if (cnt > 0)
         copySource = nsnull; // * force to create a new one and
                              // * continue grouping the messages
     }
   }
 
   // undo stuff
-  if (NS_SUCCEEDED(rv) && copyRequest->m_allowUndo && copyRequest->m_copySourceArray.Count() > 1 &&
+  if (NS_SUCCEEDED(rv) && copyRequest->m_allowUndo && copyRequest->m_copySourceArray.Length() > 1 &&
       copyRequest->m_txnMgr)
     copyRequest->m_txnMgr->BeginBatch();
 
 done:
 
     if (NS_FAILED(rv))
       delete copyRequest;
     else
@@ -641,17 +627,17 @@ done:
 }
 
 NS_IMETHODIMP
 nsMsgCopyService::NotifyCompletion(nsISupports* aSupport,
                                    nsIMsgFolder* dstFolder,
                                    nsresult result)
 {
   nsCopyRequest* copyRequest = nsnull;
-  PRInt32 numOrigRequests = m_copyRequests.Count();
+  PRUint32 numOrigRequests = m_copyRequests.Length();
   do
   {
     // loop for copy requests, because if we do a cross server folder copy,
     // we'll have a copy request for the folder copy, which will in turn
     // generate a copy request for the messages in the folder, which
     // will have the same src support.
     copyRequest = FindRequest(aSupport, dstFolder);
 
@@ -662,21 +648,20 @@ nsMsgCopyService::NotifyCompletion(nsISu
       // a new copy. We want to ignore any such request here, because it wasn't
       // the one that was completed. So we keep track of how many original
       // requests there were.
       if (m_copyRequests.IndexOf(copyRequest) >= numOrigRequests)
         break;
       // check if this copy request is done by making sure all the
       // sources have been processed.
       PRInt32 sourceIndex, sourceCount;
-      sourceCount = copyRequest->m_copySourceArray.Count();
+      sourceCount = copyRequest->m_copySourceArray.Length();
       for (sourceIndex = 0; sourceIndex < sourceCount;)
       {
-        if (!((nsCopySource*)
-            copyRequest->m_copySourceArray.ElementAt(sourceIndex))->m_processed)
+        if (!(copyRequest->m_copySourceArray.ElementAt(sourceIndex))->m_processed)
             break;
          sourceIndex++;
       }
       // if all sources processed, mark the request as processed
       if (sourceIndex >= sourceCount)
         copyRequest->m_processed = PR_TRUE;
       // if this request is done, or failed, clear it.
       if (copyRequest->m_processed || NS_FAILED(result))
--- a/mailnews/base/src/nsMsgCopyService.h
+++ b/mailnews/base/src/nsMsgCopyService.h
@@ -40,17 +40,16 @@
 
 #include "nscore.h"
 #include "nsIMsgCopyService.h"
 #include "nsCOMPtr.h"
 #include "nsIMsgFolder.h"
 #include "nsIMsgHdr.h"
 #include "nsIMsgWindow.h"
 #include "nsIMutableArray.h"
-#include "nsVoidArray.h"
 
 typedef enum _nsCopyRequestType
 {
     nsCopyMessagesType = 0x0,
     nsCopyFileMessageType = 0x1,
     nsCopyFoldersType = 0x2
 } nsCopyRequestType;
 
@@ -90,17 +89,17 @@ public:
 	nsCOMPtr<nsITransactionManager> m_txnMgr;
     nsCopyRequestType m_requestType;
     PRBool m_isMoveOrDraftOrTemplate;
     PRBool m_allowUndo;
     PRBool m_processed;
     PRUint32 m_newMsgFlags;
     nsCString m_newMsgKeywords;
     nsString m_dstFolderName;      // used for copy folder.
-    nsVoidArray m_copySourceArray; // array of nsCopySource
+    nsTArray<nsCopySource*> m_copySourceArray; // array of nsCopySource
 };
 
 class nsMsgCopyService : public nsIMsgCopyService
 {
 public:
 	nsMsgCopyService();
 	virtual ~nsMsgCopyService();
 	
@@ -111,13 +110,13 @@ public:
 private:
 
     nsresult ClearRequest(nsCopyRequest* aRequest, nsresult rv);
     nsresult DoCopy(nsCopyRequest* aRequest);
     nsresult DoNextCopy();
     nsCopyRequest* FindRequest(nsISupports* aSupport, nsIMsgFolder* dstFolder);
     nsresult QueueRequest(nsCopyRequest* aRequest, PRBool *aCopyImmediately);
 
-    nsVoidArray m_copyRequests;
+    nsTArray<nsCopyRequest*> m_copyRequests;
 };
 
 
 #endif