reduce the amount of memory allocated by the charset menu by 600k r=brendan,cata
This commit is contained in:
Родитель
aabd552127
Коммит
c5bedda141
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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<nsIEnumerator> components;
|
||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(components));
|
||||
nsCOMPtr<nsIEnumerator> enumerator;
|
||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsCOMPtr<nsIRegistryEnumerator> 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<nsISupports> base;
|
||||
nsCOMPtr<nsIRegistryNode> node;
|
||||
char * name = NULL;
|
||||
const char *name;
|
||||
nsAutoString fullName; fullName.AssignWithConversion(aAddPrefix);
|
||||
nsCOMPtr<nsIAtom> 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<nsIEnumerator> components;
|
||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(components));
|
||||
nsCOMPtr<nsIEnumerator> enumerator;
|
||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsCOMPtr<nsIRegistryEnumerator> 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<nsISupports> base;
|
||||
nsCOMPtr<nsIRegistryNode> node;
|
||||
char * src = NULL;
|
||||
char * dest = NULL;
|
||||
const char *name;
|
||||
char *src;
|
||||
char *dest;
|
||||
nsAutoString fullName;
|
||||
nsCOMPtr<nsIAtom> 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<nsIAtom> atom;
|
||||
nsresult res = GetCharsetAtom(aCharset->GetUnicode(), getter_AddRefs(atom));
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
|
Загрузка…
Ссылка в новой задаче