diff --git a/mozilla/intl/uconv/src/nsCharsetAliasImp.cpp b/mozilla/intl/uconv/src/nsCharsetAliasImp.cpp index daee53e19f0..01ca070d474 100644 --- a/mozilla/intl/uconv/src/nsCharsetAliasImp.cpp +++ b/mozilla/intl/uconv/src/nsCharsetAliasImp.cpp @@ -79,23 +79,23 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsString& aAlias, nsString& oR nsAutoString aKey; aAlias.ToLowerCase(aKey); oResult.SetLength(0); - if(nsnull == mDelegate) { - if(aKey.EqualsWithConversion("utf-8")) { - oResult.AssignWithConversion("UTF-8"); - return NS_OK; - } - if(aKey.EqualsWithConversion("iso-8859-1")) { - oResult.AssignWithConversion("ISO-8859-1"); - return NS_OK; - } - nsAutoString propertyURL; propertyURL.AssignWithConversion("resource:/res/charsetalias.properties"); - - // we may need to protect the following section with a lock so we won't call the - // 'new nsURLProperties' from two different threads - mDelegate = new nsURLProperties( propertyURL ); - NS_ASSERTION(mDelegate, "cannot create nsURLProperties"); - if(nsnull == mDelegate) - return NS_ERROR_OUT_OF_MEMORY; + if(!mDelegate) { + if(aKey.EqualsWithConversion("utf-8")) { + oResult.AssignWithConversion("UTF-8"); + return NS_OK; + } + if(aKey.EqualsWithConversion("iso-8859-1")) { + oResult.AssignWithConversion("ISO-8859-1"); + return NS_OK; + } + nsAutoString propertyURL; propertyURL.AssignWithConversion("resource:/res/charsetalias.properties"); + + // we may need to protect the following section with a lock so we won't call the + // 'new nsURLProperties' from two different threads + mDelegate = new nsURLProperties( propertyURL ); + NS_ASSERTION(mDelegate, "cannot create nsURLProperties"); + if(nsnull == mDelegate) + return NS_ERROR_OUT_OF_MEMORY; } return mDelegate->Get(aKey, oResult); } diff --git a/mozilla/intl/uconv/src/nsCharsetConverterManager.cpp b/mozilla/intl/uconv/src/nsCharsetConverterManager.cpp index 8d3b2a1b030..969c9ddf47b 100644 --- a/mozilla/intl/uconv/src/nsCharsetConverterManager.cpp +++ b/mozilla/intl/uconv/src/nsCharsetConverterManager.cpp @@ -23,6 +23,7 @@ #define NS_IMPL_IDS +#include "nsCOMPtr.h" #include "nsString.h" #include "nsICharsetAlias.h" #include "nsIRegistry.h" @@ -301,7 +302,7 @@ nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle, } nsresult nsCharsetConverterManager::GetRegistryEnumeration( - char * aRegistryKey, + char * aRegistryKey, char * aAddPrefix, nsISupportsArray ** aArray) { @@ -330,38 +331,32 @@ nsresult nsCharsetConverterManager::GetRegistryEnumeration( if (NS_FAILED(res)) return res; // enumerate subtrees - nsCOMPtr components; - res = registry->EnumerateSubtrees(key, getter_AddRefs(components)); + nsCOMPtr enumerator; + res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator)); if (NS_FAILED(res)) return res; + + nsCOMPtr components = do_QueryInterface(enumerator, &res); + if (NS_FAILED(res)) return res; + res = components->First(); if (NS_FAILED(res)) return res; while (NS_OK != components->IsDone()) { - nsCOMPtr base; - nsCOMPtr node; - char * name = NULL; + const char *name; nsAutoString fullName; fullName.AssignWithConversion(aAddPrefix); nsCOMPtr atom; - res = components->CurrentItem(getter_AddRefs(base)); - if (NS_FAILED(res)) goto done1; - - node = do_QueryInterface(base, &res); - if (NS_FAILED(res)) goto done1; - - res = node->GetNameUTF8(&name); - if (NS_FAILED(res)) goto done1; + res = components->CurrentItemInPlaceUTF8(&key, &name); + if (NS_FAILED(res)) goto next; fullName.AppendWithConversion(name); res = GetCharsetAtom(fullName.GetUnicode(), getter_AddRefs(atom)); - if (NS_FAILED(res)) goto done1; + if (NS_FAILED(res)) goto next; res = array->AppendElement(atom); - if (NS_FAILED(res)) goto done1; - -done1: - if (name != NULL) nsCRT::free(name); + if (NS_FAILED(res)) goto next; +next: res = components->Next(); if (NS_FAILED(res)) break; // this is NOT supposed to fail! } @@ -408,27 +403,24 @@ nsresult nsCharsetConverterManager::GetRegistryEnumeration2( if (NS_FAILED(res)) return res; // enumerate subtrees - nsCOMPtr components; - res = registry->EnumerateSubtrees(key, getter_AddRefs(components)); + nsCOMPtr enumerator; + res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator)); if (NS_FAILED(res)) return res; + + nsCOMPtr components = do_QueryInterface(enumerator, &res); + if (NS_FAILED(res)) return res; + res = components->First(); if (NS_FAILED(res)) return res; while (NS_OK != components->IsDone()) { - nsCOMPtr base; - nsCOMPtr node; - char * src = NULL; - char * dest = NULL; + const char *name; + char *src; + char *dest; nsAutoString fullName; nsCOMPtr atom; - res = components->CurrentItem(getter_AddRefs(base)); - if (NS_FAILED(res)) goto done1; - - node = do_QueryInterface(base, &res); - if (NS_FAILED(res)) goto done1; - - res = node->GetKey(&key); + res = components->CurrentItemInPlaceUTF8(&key, &name); if (NS_FAILED(res)) goto done1; res = registry->GetStringUTF8(key, "source", &src); @@ -525,6 +517,8 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup( if (aResult == NULL) return NS_ERROR_NULL_POINTER; *aResult = NULL; + nsAutoString prop; prop.AssignWithConversion(".LangGroup"); + nsCOMPtr atom; nsresult res = GetCharsetAtom(aCharset->GetUnicode(), getter_AddRefs(atom)); if (NS_FAILED(res)) return res;