Ignore:
Timestamp:
Dec 4, 2014, 4:59:33 PM (10 years ago)
Author:
[email protected]
Message:

Removed the concept of ParserArenaRefCounted
https://bugs.webkit.org/show_bug.cgi?id=139277

Reviewed by Oliver Hunt.

This is a step toward a parser speedup.

Now that we have a clear root node type for each parse tree, there's no
need to have a concept for "I might be refcounted or arena allocated".
Instead, we can just use unique_ptr to manage the tree as a whole.

  • API/JSScriptRef.cpp:

(parseScript):

  • builtins/BuiltinExecutables.cpp:

(JSC::BuiltinExecutables::createBuiltinExecutable): Updated for type change.

  • bytecode/UnlinkedCodeBlock.cpp:

(JSC::generateFunctionCodeBlock): Use unique_ptr. No need to call
destroyData() explicitly: the unique_ptr destructor will do everything
we need, as Bjarne intended.

  • parser/NodeConstructors.h:

(JSC::ParserArenaRoot::ParserArenaRoot):
(JSC::ParserArenaRefCounted::ParserArenaRefCounted): Deleted.

  • parser/Nodes.cpp:

(JSC::ScopeNode::ScopeNode):
(JSC::ProgramNode::ProgramNode):
(JSC::EvalNode::EvalNode):
(JSC::FunctionNode::FunctionNode):
(JSC::ProgramNode::create): Deleted.
(JSC::EvalNode::create): Deleted.
(JSC::FunctionNode::create): Deleted. All special create semantics can
just go away now that we play by C++ constructor / destructor rules.

  • parser/Nodes.h:

(JSC::ParserArenaRoot::parserArena):
(JSC::ParserArenaRoot::~ParserArenaRoot): Just a normal class now, which
holds onto the whole parse tree by virtue of owning the arena in which
all the parsed nodes (except for itself) were allocated.

(JSC::ProgramNode::closedVariables):
(JSC::ParserArenaRefCounted::~ParserArenaRefCounted): Deleted.

(JSC::ScopeNode::destroyData): Deleted. No need to destroy anything
explicitly anymore -- we can just rely on destructors.

(JSC::ScopeNode::parserArena): Deleted.

  • parser/Parser.h:

(JSC::Parser<LexerType>::parse):
(JSC::parse): unique_ptr all the things.

  • parser/ParserArena.cpp:

(JSC::ParserArena::reset):
(JSC::ParserArena::isEmpty):
(JSC::ParserArena::contains): Deleted.
(JSC::ParserArena::last): Deleted.
(JSC::ParserArena::removeLast): Deleted.
(JSC::ParserArena::derefWithArena): Deleted.

  • parser/ParserArena.h:

(JSC::ParserArena::swap): Much delete. Such wow.

  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):

  • runtime/Completion.cpp:

(JSC::checkSyntax):

  • runtime/Executable.cpp:

(JSC::ProgramExecutable::checkSyntax): unique_ptr all the things.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/parser/Parser.h

    r176756 r176825  
    403403
    404404    template <class ParsedNode>
    405     PassRefPtr<ParsedNode> parse(ParserError&, bool needReparsingAdjustment);
     405    std::unique_ptr<ParsedNode> parse(ParserError&, bool needReparsingAdjustment);
    406406
    407407    JSTextPosition positionBeforeLastNewline() const { return m_lexer->positionBeforeLastNewline(); }
     
    862862template <typename LexerType>
    863863template <class ParsedNode>
    864 PassRefPtr<ParsedNode> Parser<LexerType>::parse(ParserError& error, bool needReparsingAdjustment)
     864std::unique_ptr<ParsedNode> Parser<LexerType>::parse(ParserError& error, bool needReparsingAdjustment)
    865865{
    866866    int errLine;
     
    893893    }
    894894
    895     RefPtr<ParsedNode> result;
     895    std::unique_ptr<ParsedNode> result;
    896896    if (m_sourceElements) {
    897897        JSTokenLocation endLocation;
     
    900900        endLocation.startOffset = m_lexer->currentOffset();
    901901        unsigned endColumn = endLocation.startOffset - endLocation.lineStartOffset;
    902         result = ParsedNode::create(m_parserArena,
     902        result = std::make_unique<ParsedNode>(m_parserArena,
    903903                                    startLocation,
    904904                                    endLocation,
     
    937937    }
    938938
    939     return result.release();
     939    return result;
    940940}
    941941
    942942template <class ParsedNode>
    943 PassRefPtr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ParserError& error, JSTextPosition* positionBeforeLastNewline = 0, bool needReparsingAdjustment = false)
     943std::unique_ptr<ParsedNode> parse(VM* vm, const SourceCode& source, FunctionParameters* parameters, const Identifier& name, JSParserStrictness strictness, JSParserMode parserMode, ParserError& error, JSTextPosition* positionBeforeLastNewline = 0, bool needReparsingAdjustment = false)
    944944{
    945945    SamplingRegion samplingRegion("Parsing");
     
    948948    if (source.provider()->source().is8Bit()) {
    949949        Parser<Lexer<LChar>> parser(vm, source, parameters, name, strictness, parserMode);
    950         RefPtr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
     950        std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
    951951        if (positionBeforeLastNewline)
    952952            *positionBeforeLastNewline = parser.positionBeforeLastNewline();
     
    957957            result->setClosedVariables(parser.closedVariables());
    958958        }
    959         return result.release();
     959        return result;
    960960    }
    961961    Parser<Lexer<UChar>> parser(vm, source, parameters, name, strictness, parserMode);
    962     RefPtr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
     962    std::unique_ptr<ParsedNode> result = parser.parse<ParsedNode>(error, needReparsingAdjustment);
    963963    if (positionBeforeLastNewline)
    964964        *positionBeforeLastNewline = parser.positionBeforeLastNewline();
    965     return result.release();
     965    return result;
    966966}
    967967
Note: See TracChangeset for help on using the changeset viewer.