mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-03-05 00:02:37 +00:00
reduce the amount of memory allocated by the charset menu by 600k r=brendan,cata
This commit is contained in:
parent
3ed709f662
commit
1376983623
@ -79,23 +79,23 @@ NS_IMETHODIMP nsCharsetAlias2::GetPreferred(const nsString& aAlias, nsString& oR
|
|||||||
nsAutoString aKey;
|
nsAutoString aKey;
|
||||||
aAlias.ToLowerCase(aKey);
|
aAlias.ToLowerCase(aKey);
|
||||||
oResult.SetLength(0);
|
oResult.SetLength(0);
|
||||||
if(nsnull == mDelegate) {
|
if(!mDelegate) {
|
||||||
if(aKey.EqualsWithConversion("utf-8")) {
|
if(aKey.EqualsWithConversion("utf-8")) {
|
||||||
oResult.AssignWithConversion("UTF-8");
|
oResult.AssignWithConversion("UTF-8");
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
if(aKey.EqualsWithConversion("iso-8859-1")) {
|
if(aKey.EqualsWithConversion("iso-8859-1")) {
|
||||||
oResult.AssignWithConversion("ISO-8859-1");
|
oResult.AssignWithConversion("ISO-8859-1");
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
nsAutoString propertyURL; propertyURL.AssignWithConversion("resource:/res/charsetalias.properties");
|
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
|
// we may need to protect the following section with a lock so we won't call the
|
||||||
// 'new nsURLProperties' from two different threads
|
// 'new nsURLProperties' from two different threads
|
||||||
mDelegate = new nsURLProperties( propertyURL );
|
mDelegate = new nsURLProperties( propertyURL );
|
||||||
NS_ASSERTION(mDelegate, "cannot create nsURLProperties");
|
NS_ASSERTION(mDelegate, "cannot create nsURLProperties");
|
||||||
if(nsnull == mDelegate)
|
if(nsnull == mDelegate)
|
||||||
return NS_ERROR_OUT_OF_MEMORY;
|
return NS_ERROR_OUT_OF_MEMORY;
|
||||||
}
|
}
|
||||||
return mDelegate->Get(aKey, oResult);
|
return mDelegate->Get(aKey, oResult);
|
||||||
}
|
}
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#define NS_IMPL_IDS
|
#define NS_IMPL_IDS
|
||||||
|
|
||||||
|
#include "nsCOMPtr.h"
|
||||||
#include "nsString.h"
|
#include "nsString.h"
|
||||||
#include "nsICharsetAlias.h"
|
#include "nsICharsetAlias.h"
|
||||||
#include "nsIRegistry.h"
|
#include "nsIRegistry.h"
|
||||||
@ -301,7 +302,7 @@ nsresult nsCharsetConverterManager::GetBundleValue(nsIStringBundle * aBundle,
|
|||||||
}
|
}
|
||||||
|
|
||||||
nsresult nsCharsetConverterManager::GetRegistryEnumeration(
|
nsresult nsCharsetConverterManager::GetRegistryEnumeration(
|
||||||
char * aRegistryKey,
|
char * aRegistryKey,
|
||||||
char * aAddPrefix,
|
char * aAddPrefix,
|
||||||
nsISupportsArray ** aArray)
|
nsISupportsArray ** aArray)
|
||||||
{
|
{
|
||||||
@ -330,38 +331,32 @@ nsresult nsCharsetConverterManager::GetRegistryEnumeration(
|
|||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
// enumerate subtrees
|
// enumerate subtrees
|
||||||
nsCOMPtr<nsIEnumerator> components;
|
nsCOMPtr<nsIEnumerator> enumerator;
|
||||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(components));
|
res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator));
|
||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIRegistryEnumerator> components = do_QueryInterface(enumerator, &res);
|
||||||
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
res = components->First();
|
res = components->First();
|
||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
while (NS_OK != components->IsDone()) {
|
while (NS_OK != components->IsDone()) {
|
||||||
nsCOMPtr<nsISupports> base;
|
const char *name;
|
||||||
nsCOMPtr<nsIRegistryNode> node;
|
|
||||||
char * name = NULL;
|
|
||||||
nsAutoString fullName; fullName.AssignWithConversion(aAddPrefix);
|
nsAutoString fullName; fullName.AssignWithConversion(aAddPrefix);
|
||||||
nsCOMPtr<nsIAtom> atom;
|
nsCOMPtr<nsIAtom> atom;
|
||||||
|
|
||||||
res = components->CurrentItem(getter_AddRefs(base));
|
res = components->CurrentItemInPlaceUTF8(&key, &name);
|
||||||
if (NS_FAILED(res)) goto done1;
|
if (NS_FAILED(res)) goto next;
|
||||||
|
|
||||||
node = do_QueryInterface(base, &res);
|
|
||||||
if (NS_FAILED(res)) goto done1;
|
|
||||||
|
|
||||||
res = node->GetNameUTF8(&name);
|
|
||||||
if (NS_FAILED(res)) goto done1;
|
|
||||||
|
|
||||||
fullName.AppendWithConversion(name);
|
fullName.AppendWithConversion(name);
|
||||||
res = GetCharsetAtom(fullName.GetUnicode(), getter_AddRefs(atom));
|
res = GetCharsetAtom(fullName.GetUnicode(), getter_AddRefs(atom));
|
||||||
if (NS_FAILED(res)) goto done1;
|
if (NS_FAILED(res)) goto next;
|
||||||
|
|
||||||
res = array->AppendElement(atom);
|
res = array->AppendElement(atom);
|
||||||
if (NS_FAILED(res)) goto done1;
|
if (NS_FAILED(res)) goto next;
|
||||||
|
|
||||||
done1:
|
|
||||||
if (name != NULL) nsCRT::free(name);
|
|
||||||
|
|
||||||
|
next:
|
||||||
res = components->Next();
|
res = components->Next();
|
||||||
if (NS_FAILED(res)) break; // this is NOT supposed to fail!
|
if (NS_FAILED(res)) break; // this is NOT supposed to fail!
|
||||||
}
|
}
|
||||||
@ -408,27 +403,24 @@ nsresult nsCharsetConverterManager::GetRegistryEnumeration2(
|
|||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
// enumerate subtrees
|
// enumerate subtrees
|
||||||
nsCOMPtr<nsIEnumerator> components;
|
nsCOMPtr<nsIEnumerator> enumerator;
|
||||||
res = registry->EnumerateSubtrees(key, getter_AddRefs(components));
|
res = registry->EnumerateSubtrees(key, getter_AddRefs(enumerator));
|
||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
|
nsCOMPtr<nsIRegistryEnumerator> components = do_QueryInterface(enumerator, &res);
|
||||||
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
res = components->First();
|
res = components->First();
|
||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
|
||||||
while (NS_OK != components->IsDone()) {
|
while (NS_OK != components->IsDone()) {
|
||||||
nsCOMPtr<nsISupports> base;
|
const char *name;
|
||||||
nsCOMPtr<nsIRegistryNode> node;
|
char *src;
|
||||||
char * src = NULL;
|
char *dest;
|
||||||
char * dest = NULL;
|
|
||||||
nsAutoString fullName;
|
nsAutoString fullName;
|
||||||
nsCOMPtr<nsIAtom> atom;
|
nsCOMPtr<nsIAtom> atom;
|
||||||
|
|
||||||
res = components->CurrentItem(getter_AddRefs(base));
|
res = components->CurrentItemInPlaceUTF8(&key, &name);
|
||||||
if (NS_FAILED(res)) goto done1;
|
|
||||||
|
|
||||||
node = do_QueryInterface(base, &res);
|
|
||||||
if (NS_FAILED(res)) goto done1;
|
|
||||||
|
|
||||||
res = node->GetKey(&key);
|
|
||||||
if (NS_FAILED(res)) goto done1;
|
if (NS_FAILED(res)) goto done1;
|
||||||
|
|
||||||
res = registry->GetStringUTF8(key, "source", &src);
|
res = registry->GetStringUTF8(key, "source", &src);
|
||||||
@ -525,6 +517,8 @@ NS_IMETHODIMP nsCharsetConverterManager::GetCharsetLangGroup(
|
|||||||
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
if (aResult == NULL) return NS_ERROR_NULL_POINTER;
|
||||||
*aResult = NULL;
|
*aResult = NULL;
|
||||||
|
|
||||||
|
nsAutoString prop; prop.AssignWithConversion(".LangGroup");
|
||||||
|
|
||||||
nsCOMPtr<nsIAtom> atom;
|
nsCOMPtr<nsIAtom> atom;
|
||||||
nsresult res = GetCharsetAtom(aCharset->GetUnicode(), getter_AddRefs(atom));
|
nsresult res = GetCharsetAtom(aCharset->GetUnicode(), getter_AddRefs(atom));
|
||||||
if (NS_FAILED(res)) return res;
|
if (NS_FAILED(res)) return res;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user