Part of Bug 384490 Remove nsHashTable from mailnews - fix nsAbLDAPDirectory and nsAbMDBDirectory usages. p=Prasad Sunkari <prasad@medhas.org>,r=me,bienvenu
git-svn-id: svn://10.0.0.236/trunk@240245 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -74,6 +74,7 @@ nsAbLDAPDirectory::nsAbLDAPDirectory() :
|
||||
mContext(0),
|
||||
mLock(0)
|
||||
{
|
||||
mCache.Init();
|
||||
}
|
||||
|
||||
nsAbLDAPDirectory::~nsAbLDAPDirectory()
|
||||
@@ -226,12 +227,10 @@ NS_IMETHODIMP nsAbLDAPDirectory::HasCard(nsIAbCard* card, PRBool* hasCard)
|
||||
nsresult rv = Initiate ();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsVoidKey key (static_cast<void*>(card));
|
||||
|
||||
// Enter lock
|
||||
nsAutoLock lock (mLock);
|
||||
|
||||
*hasCard = mCache.Exists (&key);
|
||||
*hasCard = mCache.Get(card, nsnull);
|
||||
if (!*hasCard && mPerformingQuery)
|
||||
return NS_ERROR_NOT_AVAILABLE;
|
||||
|
||||
@@ -389,7 +388,7 @@ NS_IMETHODIMP nsAbLDAPDirectory::StartSearch ()
|
||||
// Enter lock
|
||||
nsAutoLock lock(mLock);
|
||||
mPerformingQuery = PR_TRUE;
|
||||
mCache.Reset();
|
||||
mCache.Clear();
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -435,11 +434,10 @@ NS_IMETHODIMP nsAbLDAPDirectory::OnSearchFoundCard(nsIAbCard* card)
|
||||
nsresult rv = Initiate();
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsVoidKey key (static_cast<void*>(card));
|
||||
// Enter lock
|
||||
{
|
||||
nsAutoLock lock(mLock);
|
||||
mCache.Put(&key, card);
|
||||
mCache.Put(card, card);
|
||||
}
|
||||
// Exit lock
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@
|
||||
#include "nsIAbDirSearchListener.h"
|
||||
#include "nsIAbLDAPDirectory.h"
|
||||
#include "nsIMutableArray.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
|
||||
class nsAbLDAPDirectory :
|
||||
public nsAbDirectoryRDFResource, // nsIRDFResource
|
||||
@@ -97,7 +97,7 @@ protected:
|
||||
PRInt32 mContext;
|
||||
PRInt32 mMaxHits;
|
||||
|
||||
nsSupportsHashtable mCache;
|
||||
nsInterfaceHashtable<nsISupportsHashKey, nsIAbCard> mCache;
|
||||
|
||||
PRLock* mLock;
|
||||
nsCOMPtr<nsIAbDirectoryQuery> mDirectoryQuery;
|
||||
|
||||
@@ -47,7 +47,6 @@
|
||||
#include "nsWeakReference.h"
|
||||
|
||||
#include "nsStringGlue.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsCOMArray.h"
|
||||
|
||||
class nsAbLDAPDirectoryQuery : public nsIAbDirectoryQuery,
|
||||
|
||||
@@ -73,6 +73,7 @@ nsAbMDBDirectory::nsAbMDBDirectory(void):
|
||||
mIsMailingList(-1),
|
||||
mPerformingQuery(PR_FALSE)
|
||||
{
|
||||
mSearchCache.Init();
|
||||
}
|
||||
|
||||
nsAbMDBDirectory::~nsAbMDBDirectory(void)
|
||||
@@ -444,13 +445,13 @@ NS_IMETHODIMP nsAbMDBDirectory::GetChildNodes(nsISimpleEnumerator* *aResult)
|
||||
return NS_NewArrayEnumerator(aResult, mSubDirectories);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(PRBool) enumerateSearchCache(nsHashKey *aKey, void *aData, void* closure)
|
||||
PR_STATIC_CALLBACK(PLDHashOperator)
|
||||
enumerateSearchCache(nsISupports *aKey, nsCOMPtr<nsIAbCard> &aData, void* aClosure)
|
||||
{
|
||||
nsIMutableArray* array = static_cast<nsIMutableArray*>(closure);
|
||||
nsIAbCard* card = static_cast<nsIAbCard*>(aData);
|
||||
nsIMutableArray* array = static_cast<nsIMutableArray*>(aClosure);
|
||||
|
||||
array->AppendElement(card, PR_FALSE);
|
||||
return PR_TRUE;
|
||||
array->AppendElement(aData, PR_FALSE);
|
||||
return PL_DHASH_NEXT;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::GetChildCards(nsISimpleEnumerator* *result)
|
||||
@@ -635,8 +636,7 @@ NS_IMETHODIMP nsAbMDBDirectory::HasCard(nsIAbCard *cards, PRBool *hasCard)
|
||||
|
||||
if (mIsQueryURI)
|
||||
{
|
||||
nsVoidKey key (static_cast<void*>(cards));
|
||||
*hasCard = mSearchCache.Exists (&key);
|
||||
*hasCard = mSearchCache.Get(cards, nsnull);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -952,7 +952,7 @@ NS_IMETHODIMP nsAbMDBDirectory::StartSearch()
|
||||
nsresult rv;
|
||||
|
||||
mPerformingQuery = PR_TRUE;
|
||||
mSearchCache.Reset();
|
||||
mSearchCache.Clear();
|
||||
|
||||
nsCOMPtr<nsIAbDirectoryQueryArguments> arguments = do_CreateInstance(NS_ABDIRECTORYQUERYARGUMENTS_CONTRACTID,&rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
@@ -1013,8 +1013,7 @@ NS_IMETHODIMP nsAbMDBDirectory::OnSearchFinished(PRInt32 aResult,
|
||||
|
||||
NS_IMETHODIMP nsAbMDBDirectory::OnSearchFoundCard(nsIAbCard* card)
|
||||
{
|
||||
nsVoidKey key (static_cast<void*>(card));
|
||||
mSearchCache.Put (&key, card);
|
||||
mSearchCache.Put(card, card);
|
||||
|
||||
// TODO
|
||||
// Search is synchronous so asserting on the
|
||||
|
||||
@@ -52,7 +52,7 @@
|
||||
#include "nsDirPrefs.h"
|
||||
#include "nsIAbDirectorySearch.h"
|
||||
#include "nsIAbDirSearchListener.h"
|
||||
#include "nsHashtable.h"
|
||||
#include "nsInterfaceHashtable.h"
|
||||
#include "nsAbDirectoryRDFResource.h"
|
||||
#include "nsIAddrDBListener.h"
|
||||
|
||||
@@ -126,7 +126,7 @@ protected:
|
||||
|
||||
PRInt32 mContext;
|
||||
PRBool mPerformingQuery;
|
||||
nsSupportsHashtable mSearchCache;
|
||||
nsInterfaceHashtable<nsISupportsHashKey, nsIAbCard> mSearchCache;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user