Bug 22986 Address book sort is extremely slow, r=nhotta+bienvenu

This commit is contained in:
chuang%netscape.com 2000-02-11 22:17:23 +00:00
Родитель 76de968c08
Коммит c3e67f21a0
4 изменённых файлов: 67 добавлений и 38 удалений

Просмотреть файл

@ -25,13 +25,15 @@
#include "nsIAbCard.idl"
#include "nsIAbDirectory.idl"
%{C++
#include "mdb.h"
#include "nsString.h"
%}
[ptr] native nsIMdbTableRowCursor(nsIMdbTableRowCursor);
[ptr] native nsIMdbEnv(nsIMdbEnv);
[ptr] native nsIMdbRow(nsIMdbRow);
%{C++
#include "mdb.h"
%}
[ref] native nsStringRef(nsString);
[scriptable, uuid(A4186D8B-1DD0-11d3-A303-001083003D0C)]
@ -110,4 +112,7 @@ interface nsIAddrDatabase : nsIAddrDBAnnouncer {
[noscript] void addCustom3(in nsIMdbRow row, in string value);
[noscript] void addCustom4(in nsIMdbRow row, in string value);
[noscript] void addNotes(in nsIMdbRow row, in string value);
[noscript] void createCollationKey(in wstring sourceStr, in nsStringRef resultStr);
};

Просмотреть файл

@ -33,21 +33,12 @@
#include "rdf.h"
#include "nsCOMPtr.h"
#include "nsICollation.h"
#include "nsILocale.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
#include "nsCollationCID.h"
#include "nsAddrDatabase.h"
#include "nsIAddrBookSession.h"
#include "nsIPref.h"
static NS_DEFINE_CID(kAddressBookDBCID, NS_ADDRDATABASE_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
static NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
@ -821,33 +812,16 @@ NS_IMETHODIMP nsAbCardProperty::CopyCard(nsIAbCard* srcCard)
NS_IMETHODIMP nsAbCardProperty::GetCollationKey(const PRUnichar *str, PRUnichar **key)
{
nsresult rv;
nsAutoString convertStr(str);
nsresult rv = NS_OK;
nsAutoString resultStr;
nsCOMPtr<nsILocale> locale;
nsCOMPtr<nsICollation> collationKeyGenerator;
NS_WITH_SERVICE(nsILocaleService, localeSvc, kLocaleServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv) && locale)
if (mCardDatabase)
{
nsCOMPtr <nsICollationFactory> factory;
rv = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL,
kICollationFactoryIID, getter_AddRefs(factory));
if (NS_SUCCEEDED(rv) && factory)
{
rv = factory->CreateCollation(locale, getter_AddRefs(collationKeyGenerator));
if (NS_SUCCEEDED(rv) && collationKeyGenerator)
{
rv = collationKeyGenerator->CreateSortKey(kCollationCaseInSensitive, convertStr, resultStr);
*key = resultStr.ToNewUnicode();
}
}
rv = mCardDatabase->CreateCollationKey(str, resultStr);
*key = resultStr.ToNewUnicode();
}
else
rv = NS_ERROR_FAILURE;
return rv;
}

Просмотреть файл

@ -38,9 +38,12 @@
#include "nsIServiceManager.h"
#include "nsRDFCID.h"
#include "nsICollation.h"
#include "nsILocale.h"
#include "nsLocaleCID.h"
#include "nsILocaleService.h"
#include "nsCollationCID.h"
#include "nsMorkCID.h"
#include "nsIPref.h"
#include "nsIMdbFactoryFactory.h"
@ -48,6 +51,9 @@
static NS_DEFINE_CID(kCMorkFactory, NS_MORK_CID);
static NS_DEFINE_CID(kAddrBookSessionCID, NS_ADDRBOOKSESSION_CID);
static NS_DEFINE_CID(kLocaleServiceCID, NS_LOCALESERVICE_CID);
static NS_DEFINE_CID(kCollationFactoryCID, NS_COLLATIONFACTORY_CID);
static NS_DEFINE_IID(kICollationFactoryIID, NS_ICOLLATIONFACTORY_IID);
/* The definition is nsAddressBook.cpp */
extern const char *kCardDataSourceRoot;
@ -2732,3 +2738,38 @@ NS_IMETHODIMP nsAddrDatabase::GetCardForEmailAddress(nsIAbDirectory *directory,
return rv;
}
nsresult nsAddrDatabase::GetCollationKeyGenerator()
{
nsresult rv = NS_OK;
if (!m_collationKeyGenerator)
{
nsCOMPtr<nsILocale> locale;
NS_WITH_SERVICE(nsILocaleService, localeSvc, kLocaleServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
rv = localeSvc->GetApplicationLocale(getter_AddRefs(locale));
if (NS_SUCCEEDED(rv) && locale)
{
nsCOMPtr <nsICollationFactory> factory;
rv = nsComponentManager::CreateInstance(kCollationFactoryCID, NULL,
kICollationFactoryIID, getter_AddRefs(factory));
if (NS_SUCCEEDED(rv) && factory)
{
rv = factory->CreateCollation(locale, getter_AddRefs(m_collationKeyGenerator));
}
}
}
return rv;
}
NS_IMETHODIMP nsAddrDatabase::CreateCollationKey(const PRUnichar* sourceStr, nsString& resultStr)
{
nsString sourceString(sourceStr);
nsresult rv = GetCollationKeyGenerator();
if (NS_SUCCEEDED(rv) && m_collationKeyGenerator)
rv = m_collationKeyGenerator->CreateSortKey(kCollationCaseInSensitive, sourceString, resultStr) ;
return rv;
}

Просмотреть файл

@ -30,6 +30,8 @@
#include "nsFileSpec.h"
#include "nsIAddrDBListener.h"
#include "nsISupportsArray.h"
#include "nsCOMPtr.h"
#include "nsICollation.h"
typedef enum
{
@ -212,6 +214,8 @@ public:
NS_IMETHOD AddNotes(nsIMdbRow * row, const char * value)
{ return AddCharStringColumn(row, m_NotesColumnToken, value); }
NS_IMETHOD CreateCollationKey(const PRUnichar *sourceStr, nsString& resultStr);
//////////////////////////////////////////////////////////////////////////////
// nsAddrDatabase methods:
@ -273,6 +277,8 @@ protected:
void GetAnonymousAttributesFromCard(nsIAbCard* card);
nsresult FindAttributeRow(nsIMdbTable* pTable, mdb_token columnToken, nsIMdbRow** row);
nsresult GetCollationKeyGenerator();
static nsVoidArray/*<nsAddrDatabase>*/* GetDBCache();
static nsVoidArray/*<nsAddrDatabase>*/* m_dbCache;
@ -348,6 +354,9 @@ protected:
mdb_token m_AddressCharSetColumnToken;
nsIAbDirectory* m_dbDirectory;
nsCOMPtr<nsICollation> m_collationKeyGenerator;
};
#endif