Bug 404386 - nsScanner construction is 5% of setting innerHTML. r=mrbkap,smontagu. sr=jst. a=blocking1.9.
git-svn-id: svn://10.0.0.236/trunk@244394 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -48,6 +48,7 @@
|
||||
#include "nsICachingChannel.h"
|
||||
#include "nsICacheEntryDescriptor.h"
|
||||
#include "nsICharsetAlias.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "CNavDTD.h"
|
||||
#include "prenv.h"
|
||||
@@ -154,6 +155,9 @@ public:
|
||||
|
||||
//-------------- End ParseContinue Event Definition ------------------------
|
||||
|
||||
nsICharsetAlias* nsParser::sCharsetAliasService = nsnull;
|
||||
nsICharsetConverterManager* nsParser::sCharsetConverterManager = nsnull;
|
||||
|
||||
/**
|
||||
* This gets called when the htmlparser module is initialized.
|
||||
*/
|
||||
@@ -204,6 +208,17 @@ nsParser::Init()
|
||||
}
|
||||
}
|
||||
|
||||
nsCOMPtr<nsICharsetAlias> charsetAlias =
|
||||
do_GetService(NS_CHARSETALIAS_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> charsetConverter =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
|
||||
charsetAlias.swap(sCharsetAliasService);
|
||||
charsetConverter.swap(sCharsetConverterManager);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
@@ -216,9 +231,11 @@ void nsParser::Shutdown()
|
||||
{
|
||||
delete sParserDataListeners;
|
||||
sParserDataListeners = nsnull;
|
||||
|
||||
NS_IF_RELEASE(sCharsetAliasService);
|
||||
NS_IF_RELEASE(sCharsetConverterManager);
|
||||
}
|
||||
|
||||
|
||||
#ifdef DEBUG
|
||||
static PRBool gDumpContent=PR_FALSE;
|
||||
#endif
|
||||
|
||||
@@ -90,6 +90,8 @@
|
||||
#include "nsIUnicharStreamListener.h"
|
||||
#include "nsCycleCollectionParticipant.h"
|
||||
|
||||
class nsICharsetConverterManager;
|
||||
class nsICharsetAlias;
|
||||
class nsIDTD;
|
||||
class nsScanner;
|
||||
class nsIProgressEventSink;
|
||||
@@ -124,7 +126,6 @@ class nsParser : public nsIParser,
|
||||
*/
|
||||
nsParser();
|
||||
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
* @update gess5/11/98
|
||||
@@ -372,6 +373,14 @@ class nsParser : public nsIParser,
|
||||
|
||||
static nsCOMArray<nsIUnicharStreamListener> *sParserDataListeners;
|
||||
|
||||
static nsICharsetAlias* GetCharsetAliasService() {
|
||||
return sCharsetAliasService;
|
||||
}
|
||||
|
||||
static nsICharsetConverterManager* GetCharsetConverterManager() {
|
||||
return sCharsetConverterManager;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
@@ -455,7 +464,8 @@ protected:
|
||||
nsCString mCharset;
|
||||
nsCString mCommandStr;
|
||||
|
||||
|
||||
static nsICharsetAlias* sCharsetAliasService;
|
||||
static nsICharsetConverterManager* sCharsetConverterManager;
|
||||
|
||||
public:
|
||||
|
||||
|
||||
@@ -103,7 +103,6 @@ nsScanner::nsScanner(const nsAString& anHTMLString, const nsACString& aCharset,
|
||||
mIncremental = PR_FALSE;
|
||||
mUnicodeDecoder = 0;
|
||||
mCharsetSource = kCharsetUninitialized;
|
||||
SetDocumentCharset(aCharset, aSource);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -149,42 +148,48 @@ nsresult nsScanner::SetDocumentCharset(const nsACString& aCharset , PRInt32 aSou
|
||||
if( aSource < mCharsetSource) // priority is lower the the current one , just
|
||||
return res;
|
||||
|
||||
nsCOMPtr<nsICharsetAlias> calias(do_GetService(NS_CHARSETALIAS_CONTRACTID, &res));
|
||||
NS_ASSERTION( nsnull != calias, "cannot find charset alias");
|
||||
if( NS_SUCCEEDED(res) && (nsnull != calias))
|
||||
nsICharsetAlias* calias = nsParser::GetCharsetAliasService();
|
||||
NS_ASSERTION(calias, "Must have the charset alias service!");
|
||||
|
||||
if (!mCharset.IsEmpty())
|
||||
{
|
||||
PRBool same = PR_FALSE;
|
||||
PRBool same;
|
||||
res = calias->Equals(aCharset, mCharset, &same);
|
||||
if(NS_SUCCEEDED(res) && same)
|
||||
{
|
||||
return NS_OK; // no difference, don't change it
|
||||
}
|
||||
// different, need to change it
|
||||
nsCAutoString charsetName;
|
||||
res = calias->GetPreferred(aCharset, charsetName);
|
||||
|
||||
if(NS_FAILED(res) && (kCharsetUninitialized == mCharsetSource) )
|
||||
{
|
||||
// failed - unknown alias , fallback to ISO-8859-1
|
||||
charsetName.AssignLiteral("ISO-8859-1");
|
||||
}
|
||||
mCharset = charsetName;
|
||||
mCharsetSource = aSource;
|
||||
|
||||
nsCOMPtr<nsICharsetConverterManager> ccm =
|
||||
do_GetService(NS_CHARSETCONVERTERMANAGER_CONTRACTID, &res);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != ccm))
|
||||
{
|
||||
nsIUnicodeDecoder * decoder = nsnull;
|
||||
res = ccm->GetUnicodeDecoderRaw(mCharset.get(), &decoder);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != decoder))
|
||||
{
|
||||
NS_IF_RELEASE(mUnicodeDecoder);
|
||||
|
||||
mUnicodeDecoder = decoder;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// different, need to change it
|
||||
nsCString charsetName;
|
||||
res = calias->GetPreferred(aCharset, charsetName);
|
||||
|
||||
if(NS_FAILED(res) && (mCharsetSource == kCharsetUninitialized))
|
||||
{
|
||||
// failed - unknown alias , fallback to ISO-8859-1
|
||||
mCharset.AssignLiteral("ISO-8859-1");
|
||||
}
|
||||
else
|
||||
{
|
||||
mCharset.Assign(charsetName);
|
||||
}
|
||||
|
||||
mCharsetSource = aSource;
|
||||
|
||||
NS_ASSERTION(nsParser::GetCharsetConverterManager(),
|
||||
"Must have the charset converter manager!");
|
||||
|
||||
nsIUnicodeDecoder * decoder = nsnull;
|
||||
res = nsParser::GetCharsetConverterManager()->
|
||||
GetUnicodeDecoderRaw(mCharset.get(), &decoder);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != decoder))
|
||||
{
|
||||
NS_IF_RELEASE(mUnicodeDecoder);
|
||||
|
||||
mUnicodeDecoder = decoder;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user