Bug 468618 - Part 2 - Replace nsMsgSearchScopeTermArray with an nsTArray; r=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Wed, 27 Oct 2010 11:34:44 +0100
changeset 6606 cff9b239245bdd08a3bffeb5857d6f1ddca8f56f
parent 6605 a124a417bc88687a8be885d57c6dfdc3e82b735e
child 6607 a30b567412fcd3167eded48efc533d6a974ecd62
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs468618
Bug 468618 - Part 2 - Replace nsMsgSearchScopeTermArray with an nsTArray; r=bienvenu
mailnews/base/search/src/nsMsgSearchSession.cpp
mailnews/base/search/src/nsMsgSearchSession.h
--- a/mailnews/base/search/src/nsMsgSearchSession.cpp
+++ b/mailnews/base/search/src/nsMsgSearchSession.cpp
@@ -178,29 +178,30 @@ nsMsgSearchSession::GetNthSearchTerm(PRI
 {
     return NS_ERROR_NOT_IMPLEMENTED;
 }
 
 /* long CountSearchScopes (); */
 NS_IMETHODIMP nsMsgSearchSession::CountSearchScopes(PRInt32 *_retval)
 {
   NS_ENSURE_ARG(_retval);
-  *_retval = m_scopeList.Count();
+  *_retval = m_scopeList.Length();
   return NS_OK;
 }
 
   /* void GetNthSearchScope (in long which, out nsMsgSearchScope scopeId, out nsIMsgFolder folder); */
 NS_IMETHODIMP
 nsMsgSearchSession::GetNthSearchScope(PRInt32 which,
                                       nsMsgSearchScopeValue *scopeId,
                                       nsIMsgFolder **folder)
 {
-  // argh, does this do an addref?
-  nsMsgSearchScopeTerm *scopeTerm = (nsMsgSearchScopeTerm *) m_scopeList.SafeElementAt(which);
-    if (!scopeTerm) return NS_ERROR_INVALID_ARG;
+  nsMsgSearchScopeTerm *scopeTerm = m_scopeList.SafeElementAt(which, nsnull);
+  if (!scopeTerm)
+    return NS_ERROR_INVALID_ARG;
+
   *scopeId = scopeTerm->m_attribute;
   *folder = scopeTerm->m_folder;
   NS_IF_ADDREF(*folder);
   return NS_OK;
 }
 
 /* void AddScopeTerm (in nsMsgSearchScopeValue scope, in nsIMsgFolder folder); */
 NS_IMETHODIMP
@@ -290,25 +291,25 @@ NS_IMETHODIMP nsMsgSearchSession::Search
 
 /* void InterruptSearch (); */
 NS_IMETHODIMP nsMsgSearchSession::InterruptSearch()
 {
   nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(m_msgWindowWeak));
   if (msgWindow)
   {
     EnableFolderNotifications(PR_TRUE);
-    if (m_idxRunningScope < m_scopeList.Count())
+    if (m_idxRunningScope < m_scopeList.Length())
       msgWindow->StopUrls();
 
-    while (m_idxRunningScope < m_scopeList.Count())
+    while (m_idxRunningScope < m_scopeList.Length())
     {
       ReleaseFolderDBRef();
       m_idxRunningScope++;
     }
-    //m_idxRunningScope = m_scopeList.Count() so it will make us not run another url
+    //m_idxRunningScope = m_scopeList.Length() so it will make us not run another url
   }
   if (m_backgroundTimer)
   {
     m_backgroundTimer->Cancel();
     NotifyListenersDone(NS_MSG_SEARCH_INTERRUPTED);
 
     m_backgroundTimer = nsnull;
   }
@@ -394,17 +395,17 @@ NS_IMETHODIMP nsMsgSearchSession::OnStop
   {
     runningAdapter->CurrentUrlDone(aExitCode);
     EnableFolderNotifications(PR_TRUE);
     ReleaseFolderDBRef();
   }
   m_idxRunningScope++;
   if (++m_urlQueueIndex < m_urlQueue.Count())
     GetNextUrl();
-  else if (m_idxRunningScope < m_scopeList.Count())
+  else if (m_idxRunningScope < m_scopeList.Length())
     DoNextSearch();
   else
     NotifyListenersDone(aExitCode);
   return NS_OK;
 }
 
 
 nsresult nsMsgSearchSession::Initialize()
@@ -423,26 +424,26 @@ nsresult nsMsgSearchSession::Initialize(
   PRUint32 numTerms;
   m_termList->Count(&numTerms);
   // Ensure that the FE has added scopes and terms to this search
   NS_ASSERTION(numTerms > 0, "no terms to search!");
   if (numTerms == 0)
     return NS_MSG_ERROR_NO_SEARCH_VALUES;
 
   // if we don't have any search scopes to search, return that code.
-  if (m_scopeList.Count() == 0)
+  if (m_scopeList.Length() == 0)
     return NS_MSG_ERROR_INVALID_SEARCH_SCOPE;
 
   m_urlQueue.Clear(); // clear out old urls, if any.
   m_idxRunningScope = 0;
   m_urlQueueIndex = 0;
 
   // If this term list (loosely specified here by the first term) should be
   // scheduled in parallel, build up a list of scopes to do the round-robin scheduling
-  for (int i = 0; i < m_scopeList.Count() && NS_SUCCEEDED(err); i++)
+  for (PRUint32 i = 0; i < m_scopeList.Length() && NS_SUCCEEDED(err); i++)
   {
     scopeTerm = m_scopeList.ElementAt(i);
     // NS_ASSERTION(scopeTerm->IsValid());
 
     err = scopeTerm->InitializeAdapter (m_termList);
   }
 
   return err;
@@ -468,24 +469,24 @@ nsresult nsMsgSearchSession::DoNextSearc
     return BuildUrlQueue ();
   else
     return SearchWOUrls();
 }
 
 
 nsresult nsMsgSearchSession::BuildUrlQueue ()
 {
-  PRInt32 i;
-  for (i = m_idxRunningScope; i < m_scopeList.Count(); i++)
+  PRUint32 i;
+  for (i = m_idxRunningScope; i < m_scopeList.Length(); i++)
   {
     nsMsgSearchScopeTerm *scope = m_scopeList.ElementAt(i);
     if (scope->m_attribute != nsMsgSearchScope::onlineMail &&
       (scope->m_attribute != nsMsgSearchScope::news && scope->m_searchServer))
       break;
-    nsCOMPtr <nsIMsgSearchAdapter> adapter = do_QueryInterface((m_scopeList.ElementAt(i))->m_adapter);
+    nsCOMPtr <nsIMsgSearchAdapter> adapter = do_QueryInterface(scope->m_adapter);
     nsCString url;
     if (adapter)
     {
       adapter->GetEncoding(getter_Copies(url));
       AddUrl (url.get());
     }
   }
 
@@ -544,17 +545,17 @@ nsresult nsMsgSearchSession::AddUrl(cons
   nsCOMPtr<nsIMsgWindow> msgWindow(do_QueryReferent(searchSession->m_msgWindowWeak));
   if (msgWindow)
     msgWindow->GetStopped(&stopped);
 
   if (done || stopped)
   {
     aTimer->Cancel();
     searchSession->m_backgroundTimer = nsnull;
-    if (searchSession->m_idxRunningScope < searchSession->m_scopeList.Count())
+    if (searchSession->m_idxRunningScope < searchSession->m_scopeList.Length())
       searchSession->DoNextSearch();
     else
       searchSession->NotifyListenersDone(NS_OK);
   }
 }
 
 nsresult nsMsgSearchSession::StartTimer()
 {
@@ -619,20 +620,19 @@ nsresult nsMsgSearchSession::NotifyListe
       listener->OnSearchDone(aStatus);
   }
   m_iListener = -1;
   return NS_OK;
 }
 
 void nsMsgSearchSession::DestroyScopeList()
 {
-  nsMsgSearchScopeTerm *scope = NULL;
-  PRInt32 count = m_scopeList.Count();
+  nsMsgSearchScopeTerm *scope = nsnull;
 
-  for (PRInt32 i = count-1; i >= 0; i--)
+  for (PRInt32 i = m_scopeList.Length() - 1; i >= 0; i--)
   {
     scope = m_scopeList.ElementAt(i);
     //    NS_ASSERTION (scope->IsValid(), "invalid search scope");
     if (scope->m_adapter)
       scope->m_adapter->ClearScope();
     delete scope;
   }
   m_scopeList.Clear();
@@ -641,17 +641,17 @@ void nsMsgSearchSession::DestroyScopeLis
 
 void nsMsgSearchSession::DestroyTermList ()
 {
     m_termList->Clear();
 }
 
 nsMsgSearchScopeTerm *nsMsgSearchSession::GetRunningScope()
 {
-    return (nsMsgSearchScopeTerm *) m_scopeList.SafeElementAt(m_idxRunningScope);
+  return m_scopeList.SafeElementAt(m_idxRunningScope, nsnull);
 }
 
 nsresult nsMsgSearchSession::TimeSlice (PRBool *aDone)
 {
   // we only do serial for now.
   return TimeSliceSerial(aDone);
 }
 
@@ -731,17 +731,17 @@ nsMsgSearchSession::EnableFolderNotifica
       folder->EnableNotifications(nsIMsgFolder::allMessageCountNotifications, aEnable, PR_FALSE);
   }
 }
 
 //this method is used for adding new hdrs to quick search view
 NS_IMETHODIMP
 nsMsgSearchSession::MatchHdr(nsIMsgDBHdr *aMsgHdr, nsIMsgDatabase *aDatabase, PRBool *aResult)
 {
-  nsMsgSearchScopeTerm *scope = (nsMsgSearchScopeTerm *)m_scopeList.SafeElementAt(0);
+  nsMsgSearchScopeTerm *scope = m_scopeList.SafeElementAt(0, nsnull);
   if (scope)
   {
     if (!scope->m_adapter)
       scope->InitializeAdapter(m_termList);
     if (scope->m_adapter)
     {
       nsAutoString nullCharset, folderCharset;
       scope->m_adapter->GetSearchCharsets(nullCharset, folderCharset);
--- a/mailnews/base/search/src/nsMsgSearchSession.h
+++ b/mailnews/base/search/src/nsMsgSearchSession.h
@@ -43,26 +43,20 @@
 #include "nsIMsgSearchSession.h"
 #include "nsIUrlListener.h"
 #include "nsIMsgWindow.h"
 #include "nsITimer.h"
 #include "nsISupportsArray.h"
 #include "nsCOMArray.h"
 #include "nsWeakReference.h"
 #include "nsTObserverArray.h"
-#include "nsMsgSearchScopeTerm.h"
 
 class nsMsgSearchAdapter;
 class nsMsgSearchBoolExpression;
-
-class nsMsgSearchScopeTermArray : public nsVoidArray
-{
-public:
-  nsMsgSearchScopeTerm *ElementAt(PRUint32 i) const { return (nsMsgSearchScopeTerm*) nsVoidArray::SafeElementAt(i); }
-};
+class nsMsgSearchScopeTerm;
 
 class nsMsgSearchSession : public nsIMsgSearchSession, public nsIUrlListener, public nsSupportsWeakReference
 {
 public:
   NS_DECL_ISUPPORTS
   NS_DECL_NSIMSGSEARCHSESSION
   NS_DECL_NSIURLLISTENER
 
@@ -81,17 +75,17 @@ protected:
   nsresult BuildUrlQueue ();
   nsresult AddUrl(const char *url);
   nsresult SearchWOUrls ();
   nsresult GetNextUrl();
   nsresult NotifyListenersDone(nsresult status);
   void EnableFolderNotifications(PRBool aEnable);
   void ReleaseFolderDBRef();
 
-  nsMsgSearchScopeTermArray m_scopeList;
+  nsTArray<nsMsgSearchScopeTerm*> m_scopeList;
   nsCOMPtr <nsISupportsArray> m_termList;
 
   nsTArray<nsCOMPtr<nsIMsgSearchNotify> > m_listenerList;
   nsTArray<PRInt32> m_listenerFlagList;
   /**
    * Iterator index for m_listenerList/m_listenerFlagList.  We used to use an
    * nsTObserverArray for m_listenerList but its auto-adjusting iterator was
    * not helping us keep our m_listenerFlagList iterator correct.
@@ -113,17 +107,17 @@ protected:
   void DestroyScopeList ();
 
   static void TimerCallback(nsITimer *aTimer, void *aClosure);
   // support for searching multiple scopes in serial
   nsresult TimeSliceSerial (PRBool *aDone);
   nsresult TimeSliceParallel ();
 
   nsMsgSearchAttribValue m_sortAttribute;
-  PRInt32 m_idxRunningScope;
+  PRUint32 m_idxRunningScope;
   nsMsgSearchType m_searchType;
   PRBool m_handlingError;
   PRInt32 m_urlQueueIndex;
   nsCStringArray m_urlQueue;
   nsCOMPtr <nsITimer> m_backgroundTimer;
   PRBool m_searchPaused;
   nsMsgSearchBoolExpression *m_expressionTree;
 };