use cstring hash keys for xf views, r=neil, bug 632966
authorDavid Bienvenu <bienvenu@nventure.com>
Thu, 10 Feb 2011 13:30:31 -0800
changeset 7123 9db390d87be41096d2c8b884c21e837ddb0f367d
parent 7122 f8a93b79758c506404bd4ccad0d5018240b62f83
child 7124 c92d62353031e70a2e31e4c543f6df87f3ad54ec
push idunknown
push userunknown
push dateunknown
reviewersneil, bug
bugs632966
use cstring hash keys for xf views, r=neil, bug 632966
mailnews/base/src/nsMsgSearchDBView.cpp
mailnews/base/src/nsMsgSearchDBView.h
--- a/mailnews/base/src/nsMsgSearchDBView.cpp
+++ b/mailnews/base/src/nsMsgSearchDBView.cpp
@@ -106,25 +106,25 @@ NS_IMETHODIMP nsMsgSearchDBView::Open(ns
     if (pCount)
       *pCount = 0;
     m_folder = nsnull;
     return rv;
 }
 
 
 PLDHashOperator
-nsMsgSearchDBView::ThreadTableCloner(const nsAString &aKey, nsIMsgThread* aThread, void* aArg)
+nsMsgSearchDBView::ThreadTableCloner(const nsACString &aKey, nsIMsgThread* aThread, void* aArg)
 {
   nsMsgSearchDBView* view = static_cast<nsMsgSearchDBView*>(aArg);
   nsresult rv = view->m_threadsTable.Put(aKey, aThread);
   return NS_SUCCEEDED(rv) ? PL_DHASH_NEXT : PL_DHASH_STOP;
 }
 
 PLDHashOperator
-nsMsgSearchDBView::MsgHdrTableCloner(const nsAString &aKey, nsIMsgDBHdr* aMsgHdr, void* aArg)
+nsMsgSearchDBView::MsgHdrTableCloner(const nsACString &aKey, nsIMsgDBHdr* aMsgHdr, void* aArg)
 {
   nsMsgSearchDBView* view = static_cast<nsMsgSearchDBView*>(aArg);
   nsresult rv = view->m_hdrsTable.Put(aKey, aMsgHdr);
   return NS_SUCCEEDED(rv) ? PL_DHASH_NEXT : PL_DHASH_STOP;
 }
 
 NS_IMETHODIMP
 nsMsgSearchDBView::CloneDBView(nsIMessenger *aMessengerInstance, nsIMsgWindow *aMsgWindow, nsIMsgDBViewCommandUpdater *aCmdUpdater, nsIMsgDBView **_retval)
@@ -1271,83 +1271,73 @@ nsMsgViewIndex nsMsgSearchDBView::FindHd
 
 // This method looks for the XF thread that corresponds to this message hdr,
 // first by looking up the message id, then references, and finally, if subject
 // threading is turned on, the subject.
 nsresult nsMsgSearchDBView::GetXFThreadFromMsgHdr(nsIMsgDBHdr *msgHdr, 
                                                   nsIMsgThread **pThread,
                                                   PRBool *foundByMessageId)
 {
-  nsAutoString hashKey;
   nsCAutoString messageId;
   msgHdr->GetMessageId(getter_Copies(messageId));
-  CopyASCIItoUTF16(messageId, hashKey);
   *pThread = nsnull;
-  m_threadsTable.Get(hashKey, pThread);
+  m_threadsTable.Get(messageId, pThread);
   // The caller may want to know if we found the thread by the msgHdr's
   // messageId
   if (foundByMessageId)
     *foundByMessageId = *pThread != nsnull;
   if (!*pThread)
   {
     PRUint16 numReferences = 0;
     msgHdr->GetNumReferences(&numReferences);
     for (PRInt32 i = numReferences - 1; i >= 0  && !*pThread; i--)
     {
       nsCAutoString reference;
       
       msgHdr->GetStringReference(i, reference);
       if (reference.IsEmpty())
         break;
 
-      CopyASCIItoUTF16(reference, hashKey);
-      m_threadsTable.Get(hashKey, pThread);
+      m_threadsTable.Get(reference, pThread);
     }
   }
   // if we're threading by subject, and we couldn't find the thread by ref,
   // just treat subject as an other ref.
   if (!*pThread && !gReferenceOnlyThreading)
   {
     nsCString subject;
     msgHdr->GetSubject(getter_Copies(subject));
     // this is the raw rfc822 subject header, so this is OK
-    CopyASCIItoUTF16(subject, hashKey);
-    m_threadsTable.Get(hashKey, pThread);
+    m_threadsTable.Get(subject, pThread);
   }
   return (*pThread) ? NS_OK : NS_ERROR_FAILURE;
 }
 
 nsresult nsMsgSearchDBView::GetMsgHdrFromHash(nsCString &reference, nsIMsgDBHdr **hdr)
 {
-  nsString hashKey;
-  CopyASCIItoUTF16(reference, hashKey);
-  return m_hdrsTable.Get(hashKey, hdr);
+  return m_hdrsTable.Get(reference, hdr);
 }
 
 nsresult nsMsgSearchDBView::GetThreadFromHash(nsCString &reference, 
                                               nsIMsgThread **thread)
 {
-  nsString hashKey;
-  CopyASCIItoUTF16(reference, hashKey);
-  return m_threadsTable.Get(hashKey, thread);
+  return m_threadsTable.Get(reference, thread);
 }
 
 nsresult nsMsgSearchDBView::AddRefToHash(nsCString &reference, 
                                          nsIMsgThread *thread)
 {
-  nsString hashKey;
-  CopyASCIItoUTF16(reference, hashKey);
   // Check if this reference is already is associated with a thread;
   // If so, don't overwrite that association.
   nsCOMPtr<nsIMsgThread> oldThread;
-  m_threadsTable.Get(hashKey, getter_AddRefs(oldThread));
+  m_threadsTable.Get(reference, getter_AddRefs(oldThread));
   if (oldThread)
     return NS_OK;
 
-  return m_threadsTable.Put(hashKey, thread);
+  return m_threadsTable.Put(reference, thread);
 }
 
 nsresult nsMsgSearchDBView::AddMsgToHashTables(nsIMsgDBHdr *msgHdr,
                                                nsIMsgThread *thread)
 {
   PRUint16 numReferences = 0;
   nsresult rv;
 
@@ -1361,34 +1351,30 @@ nsresult nsMsgSearchDBView::AddMsgToHash
       break;
 
     rv = AddRefToHash(reference, thread);
     NS_ENSURE_SUCCESS(rv, rv);
   }
 
   nsCString messageId;
   msgHdr->GetMessageId(getter_Copies(messageId));
-  nsString hashKey;
-  CopyASCIItoUTF16(messageId, hashKey);
-  m_hdrsTable.Put(hashKey, msgHdr);
+  m_hdrsTable.Put(messageId, msgHdr);
   if (!gReferenceOnlyThreading)
   {
     nsCString subject;
     msgHdr->GetSubject(getter_Copies(subject));
     // if we're threading by subject, just treat subject as an other ref.
     AddRefToHash(subject, thread);
   }
   return AddRefToHash(messageId, thread);
 }
 
 nsresult nsMsgSearchDBView::RemoveRefFromHash(nsCString &reference)
 {
-  nsString hashKey;
-  CopyASCIItoUTF16(reference, hashKey);
-  m_threadsTable.Remove(hashKey);
+  m_threadsTable.Remove(reference);
   return NS_OK;
 }
 
 nsresult nsMsgSearchDBView::RemoveMsgFromHashTables(nsIMsgDBHdr *msgHdr)
 {
   PRUint16 numReferences = 0;
   nsresult rv = NS_OK;
 
@@ -1402,19 +1388,17 @@ nsresult nsMsgSearchDBView::RemoveMsgFro
       break;
 
     rv = RemoveRefFromHash(reference);
     if (NS_FAILED(rv))
       break;
   }
   nsCString messageId;
   msgHdr->GetMessageId(getter_Copies(messageId));
-  nsString hashKey;
-  CopyASCIItoUTF16(messageId, hashKey);
-  m_hdrsTable.Remove(hashKey);
+  m_hdrsTable.Remove(messageId);
   RemoveRefFromHash(messageId);
   if (!gReferenceOnlyThreading)
   {
     nsCString subject;
     msgHdr->GetSubject(getter_Copies(subject));
     // if we're threading by subject, just treat subject as an other ref.
     RemoveRefFromHash(subject);
   }
--- a/mailnews/base/src/nsMsgSearchDBView.h
+++ b/mailnews/base/src/nsMsgSearchDBView.h
@@ -150,25 +150,25 @@ protected:
   // these are for doing threading of the search hits
 
   // used for assigning thread id's to xfview threads.
   nsMsgKey m_nextThreadId;
   // this maps message-ids and reference message ids to
   // the corresponding nsMsgXFViewThread object. If we're 
   // doing subject threading, we would throw subjects
   // into the same table.
-  nsInterfaceHashtable <nsStringHashKey, nsIMsgThread> m_threadsTable;
+  nsInterfaceHashtable <nsCStringHashKey, nsIMsgThread> m_threadsTable;
 
   // map message-ids to msg hdrs in the view, used for threading.
-  nsInterfaceHashtable <nsStringHashKey, nsIMsgDBHdr> m_hdrsTable;
+  nsInterfaceHashtable <nsCStringHashKey, nsIMsgDBHdr> m_hdrsTable;
 
-  PR_STATIC_CALLBACK(PLDHashOperator) ThreadTableCloner(const nsAString &aKey, 
+  PR_STATIC_CALLBACK(PLDHashOperator) ThreadTableCloner(const nsACString &aKey, 
                                                         nsIMsgThread* aThread, 
                                                         void* aArg);
-  PR_STATIC_CALLBACK(PLDHashOperator) MsgHdrTableCloner(const nsAString &aKey, 
+  PR_STATIC_CALLBACK(PLDHashOperator) MsgHdrTableCloner(const nsACString &aKey, 
                                                         nsIMsgDBHdr* aMsgHdr, 
                                                         void* aArg);
   virtual nsMsgGroupThread *CreateGroupThread(nsIMsgDatabase *db);
   nsresult GetXFThreadFromMsgHdr(nsIMsgDBHdr *msgHdr, nsIMsgThread **pThread,
                                  PRBool *foundByMessageId = nsnull);
   nsresult GetThreadFromHash(nsCString &reference, nsIMsgThread **thread);
   nsresult GetMsgHdrFromHash(nsCString &reference, nsIMsgDBHdr **hdr);
   nsresult AddRefToHash(nsCString &reference, nsIMsgThread *thread);