Bug 1674351 - Part 6: Merge XDRParserAtomTable into ParserAtomVectorBuilder. r=tcampbell

XDRParserAtomTable and ParserAtomVector has the same content.
Removed XDRParserAtomTable and rewrote consumers to use ParserAtomVector.

Differential Revision: https://phabricator.services.mozilla.com/D95844
This commit is contained in:
Tooru Fujisawa 2020-11-05 15:56:05 +00:00
Родитель 249249f800
Коммит 1df9ab6741
4 изменённых файлов: 15 добавлений и 17 удалений

Просмотреть файл

@ -387,6 +387,14 @@ ParserAtomVectorBuilder::ParserAtomVectorBuilder(JSRuntime* rt,
alloc_(&alloc),
entries_(entries) {}
bool ParserAtomVectorBuilder::reserve(JSContext* cx, size_t count) {
if (!entries_.reserve(count)) {
ReportOutOfMemory(cx);
return false;
}
return true;
}
JS::Result<const ParserAtom*, OOM> ParserAtomVectorBuilder::internLatin1(
JSContext* cx, const Latin1Char* latin1Ptr, HashNumber hash,
uint32_t length) {
@ -947,10 +955,10 @@ XDRResult XDRParserAtom(XDRState<mode>* xdr, const ParserAtom** atomp) {
switch (tag) {
case ParserAtomTag::Normal:
if (atomIndex >= xdr->parserAtomTable().length()) {
if (atomIndex >= xdr->frontendAtoms().length()) {
return xdr->fail(JS::TranscodeResult_Failure_BadDecode);
}
*atomp = xdr->parserAtomTable()[atomIndex];
*atomp = xdr->frontendAtoms().get(atomIndex);
break;
case ParserAtomTag::WellKnown:
if (atomIndex >= uint32_t(WellKnownAtomId::Limit)) {

Просмотреть файл

@ -576,6 +576,10 @@ class ParserAtomVectorBuilder {
ParserAtomVectorBuilder(JSRuntime* rt, LifoAlloc& alloc,
ParserAtomVector& entries);
bool reserve(JSContext* cx, size_t count);
size_t length() const { return entries_.length(); }
ParserAtom* get(size_t index) { return entries_[index]->asAtom(); }
JS::Result<const ParserAtom*, OOM> internLatin1(
JSContext* cx, const JS::Latin1Char* latin1Ptr, HashNumber hash,
uint32_t length);

Просмотреть файл

@ -316,18 +316,13 @@ static XDRResult ParserAtomTable(XDRState<mode>* xdr) {
MOZ_TRY(XDRAtomCount(xdr, &atomCount));
MOZ_ASSERT(!xdr->hasAtomTable());
if (!xdr->parserAtomTable().reserve(atomCount)) {
ReportOutOfMemory(xdr->cx());
if (!xdr->frontendAtoms().reserve(xdr->cx(), atomCount)) {
return xdr->fail(JS::TranscodeResult_Throw);
}
for (uint32_t i = 0; i < atomCount; i++) {
const frontend::ParserAtom* atom = nullptr;
MOZ_TRY(XDRParserAtomData(xdr, &atom));
if (!xdr->parserAtomTable().append(atom)) {
ReportOutOfMemory(xdr->cx());
return xdr->fail(JS::TranscodeResult_Throw);
}
}
xdr->finishAtomTable();
@ -770,7 +765,6 @@ XDRResult XDRStencilDecoder::codeStencils(
cx(), compilationInfos.initial.input.options);
auto& funInfo = compilationInfos.delazifications[i - 1];
parserAtomTable_.clear();
hasFinishedAtomTable_ = false;
frontend::ParserAtomVectorBuilder parserAtomBuilder(

Просмотреть файл

@ -45,8 +45,6 @@ using XDRResult = XDRResultT<mozilla::Ok>;
using XDRAtomTable = JS::GCVector<PreBarriered<JSAtom*>>;
using XDRAtomMap = JS::GCHashMap<PreBarriered<JSAtom*>, uint32_t>;
using XDRParserAtomTable =
Vector<const frontend::ParserAtom*, 0, SystemAllocPolicy>;
using XDRParserAtomMap = HashMap<const frontend::ParserAtom*, uint32_t>;
class XDRBufferBase {
@ -279,10 +277,6 @@ class XDRState : public XDRCoderBase {
MOZ_CRASH("does not have frontendAtoms");
}
virtual LifoAlloc& stencilAlloc() { MOZ_CRASH("does not have stencilAlloc"); }
virtual XDRParserAtomTable& parserAtomTable() {
// This accessor is only used when encoding stencils.
MOZ_CRASH("does not have parserAtomTable");
}
virtual void finishAtomTable() { MOZ_CRASH("does not have atomTable"); }
virtual bool isMainBuf() { return true; }
@ -542,7 +536,6 @@ class XDRStencilDecoder : public XDRDecoderBase {
return *parserAtomBuilder_;
}
LifoAlloc& stencilAlloc() override { return *stencilAlloc_; }
XDRParserAtomTable& parserAtomTable() override { return parserAtomTable_; }
void finishAtomTable() override { hasFinishedAtomTable_ = true; }
bool hasOptions() const override { return true; }
@ -552,7 +545,6 @@ class XDRStencilDecoder : public XDRDecoderBase {
private:
const JS::ReadOnlyCompileOptions* options_;
XDRParserAtomTable parserAtomTable_;
bool hasFinishedAtomTable_ = false;
frontend::ParserAtomVectorBuilder* parserAtomBuilder_ = nullptr;
LifoAlloc* stencilAlloc_ = nullptr;