mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-10 11:55:49 +00:00
Bug 1424468 - Stop using Encoding::ForName in HTML parser. r=hsivonen
MozReview-Commit-ID: 1rONnEXLgPf --HG-- extra : rebase_source : 081effdc2a3ee0292d73666abc7bda7b62d3a0a7
This commit is contained in:
parent
295faed3f9
commit
082293ce3e
@ -15,6 +15,7 @@ nsHtml5SpeculativeLoad::nsHtml5SpeculativeLoad()
|
||||
mIsDefer(false)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsHtml5SpeculativeLoad);
|
||||
new(&mCharsetOrSrcset) nsString;
|
||||
}
|
||||
|
||||
nsHtml5SpeculativeLoad::~nsHtml5SpeculativeLoad()
|
||||
@ -22,6 +23,9 @@ nsHtml5SpeculativeLoad::~nsHtml5SpeculativeLoad()
|
||||
MOZ_COUNT_DTOR(nsHtml5SpeculativeLoad);
|
||||
NS_ASSERTION(mOpCode != eSpeculativeLoadUninitialized,
|
||||
"Uninitialized speculative load.");
|
||||
if (mOpCode != eSpeculativeLoadSetDocumentCharset) {
|
||||
mCharsetOrSrcset.~nsString();
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
@ -73,12 +77,10 @@ nsHtml5SpeculativeLoad::Perform(nsHtml5TreeOpExecutor* aExecutor)
|
||||
aExecutor->ProcessOfflineManifest(mUrlOrSizes);
|
||||
break;
|
||||
case eSpeculativeLoadSetDocumentCharset: {
|
||||
nsAutoCString narrowName;
|
||||
CopyUTF16toUTF8(mCharsetOrSrcset, narrowName);
|
||||
NS_ASSERTION(mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Length() == 1,
|
||||
"Unexpected charset source string");
|
||||
int32_t intSource = (int32_t)mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.First();
|
||||
aExecutor->SetDocumentCharsetAndSource(Encoding::ForName(narrowName),
|
||||
aExecutor->SetDocumentCharsetAndSource(WrapNotNull(mEncoding),
|
||||
intSource);
|
||||
}
|
||||
break;
|
||||
|
@ -31,6 +31,8 @@ enum eHtml5SpeculativeLoad {
|
||||
};
|
||||
|
||||
class nsHtml5SpeculativeLoad {
|
||||
using Encoding = mozilla::Encoding;
|
||||
template <typename T> using NotNull = mozilla::NotNull<T>;
|
||||
public:
|
||||
nsHtml5SpeculativeLoad();
|
||||
~nsHtml5SpeculativeLoad();
|
||||
@ -190,13 +192,14 @@ class nsHtml5SpeculativeLoad {
|
||||
* sheets. Thus, encoding decisions by the parser thread have to maintain
|
||||
* the queue order relative to true speculative loads. See bug 675499.
|
||||
*/
|
||||
inline void InitSetDocumentCharset(nsACString& aCharset,
|
||||
inline void InitSetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
int32_t aCharsetSource)
|
||||
{
|
||||
NS_PRECONDITION(mOpCode == eSpeculativeLoadUninitialized,
|
||||
"Trying to reinitialize a speculative load!");
|
||||
mOpCode = eSpeculativeLoadSetDocumentCharset;
|
||||
CopyUTF8toUTF16(aCharset, mCharsetOrSrcset);
|
||||
mCharsetOrSrcset.~nsString();
|
||||
mEncoding = aEncoding;
|
||||
mTypeOrCharsetSourceOrDocumentModeOrMetaCSPOrSizesOrIntegrity.Assign((char16_t)aCharsetSource);
|
||||
}
|
||||
|
||||
@ -257,7 +260,10 @@ class nsHtml5SpeculativeLoad {
|
||||
* or eSpeculativeLoadPictureSource, this is the value of the "srcset" attribute.
|
||||
* If the attribute is not set, this will be a void string. Otherwise it's empty.
|
||||
*/
|
||||
nsString mCharsetOrSrcset;
|
||||
union {
|
||||
nsString mCharsetOrSrcset;
|
||||
const Encoding* mEncoding;
|
||||
};
|
||||
/**
|
||||
* If mOpCode is eSpeculativeLoadSetDocumentCharset, this is a
|
||||
* one-character string whose single character's code point is to be
|
||||
|
@ -1197,10 +1197,8 @@ nsHtml5TreeBuilder::SetDocumentCharset(NotNull<const Encoding*> aEncoding,
|
||||
if (mBuilder) {
|
||||
mBuilder->SetDocumentCharsetAndSource(aEncoding, aCharsetSource);
|
||||
} else if (mSpeculativeLoadStage) {
|
||||
nsAutoCString charset;
|
||||
aEncoding->Name(charset);
|
||||
mSpeculativeLoadQueue.AppendElement()->InitSetDocumentCharset(
|
||||
charset, aCharsetSource);
|
||||
aEncoding, aCharsetSource);
|
||||
} else {
|
||||
mOpQueue.AppendElement()->Init(
|
||||
eTreeOpSetDocumentCharset, aEncoding, aCharsetSource);
|
||||
|
Loading…
Reference in New Issue
Block a user