Bug 459773 - Creating a collation is expensive

This makes a lazy getter for getting our collation saving us about 3% of places
startup time.
r=dietrich
This commit is contained in:
Shawn Wilsher 2008-10-17 06:12:52 -04:00
parent 867daf5b5f
commit 1d0921f3e0
2 changed files with 26 additions and 19 deletions

View File

@ -459,19 +459,6 @@ nsNavHistory::Init()
getter_AddRefs(mBundle));
NS_ENSURE_SUCCESS(rv, rv);
// locale
nsCOMPtr<nsILocaleService> ls = do_GetService(NS_LOCALESERVICE_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = ls->GetApplicationLocale(getter_AddRefs(mLocale));
NS_ENSURE_SUCCESS(rv, rv);
// collation
nsCOMPtr<nsICollationFactory> cfact = do_CreateInstance(
NS_COLLATIONFACTORY_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
rv = cfact->CreateCollation(mLocale, getter_AddRefs(mCollation));
NS_ENSURE_SUCCESS(rv, rv);
// date formatter
mDateFormatter = do_CreateInstance(NS_DATETIMEFORMAT_CONTRACTID, &rv);
NS_ENSURE_SUCCESS(rv, rv);
@ -7365,6 +7352,30 @@ nsNavHistory::RecalculateFrecenciesInternal(mozIStorageStatement *aStatement, PR
return NS_OK;
}
nsICollation *
nsNavHistory::GetCollation()
{
if (mCollation)
return mCollation;
// locale
nsCOMPtr<nsILocale> locale;
nsCOMPtr<nsILocaleService> ls(do_GetService(NS_LOCALESERVICE_CONTRACTID));
NS_ENSURE_TRUE(ls, nsnull);
nsresult rv = ls->GetApplicationLocale(getter_AddRefs(locale));
NS_ENSURE_SUCCESS(rv, nsnull);
// collation
nsCOMPtr<nsICollationFactory> cfact =
do_CreateInstance(NS_COLLATIONFACTORY_CONTRACTID);
NS_ENSURE_TRUE(cfact, nsnull);
rv = cfact->CreateCollation(locale, getter_AddRefs(mCollation));
NS_ENSURE_SUCCESS(rv, nsnull);
return mCollation;
}
// nsICharsetResolver **********************************************************
NS_IMETHODIMP

View File

@ -237,14 +237,11 @@ public:
/**
* These functions return non-owning references to the locale-specific
* objects for places components. Guaranteed to return non-NULL.
* objects for places components.
*/
nsIStringBundle* GetBundle()
{ return mBundle; }
nsILocale* GetLocale()
{ return mLocale; }
nsICollation* GetCollation()
{ return mCollation; }
nsICollation* GetCollation();
nsIDateTimeFormat* GetDateFormatter()
{ return mDateFormatter; }
void GetStringFromName(const PRUnichar* aName, nsACString& aResult);
@ -613,7 +610,6 @@ protected:
// localization
nsCOMPtr<nsIStringBundle> mBundle;
nsCOMPtr<nsILocale> mLocale;
nsCOMPtr<nsICollation> mCollation;
nsCOMPtr<nsIDateTimeFormat> mDateFormatter;