Changeset 28854 in webkit for trunk/JavaScriptCore/kjs/Parser.h


Ignore:
Timestamp:
Dec 18, 2007, 11:42:29 PM (17 years ago)
Author:
[email protected]
Message:

Replace post-parse pass to find declarations with logic in the parser itself

Reviewed by Geoff.

Instead of finding declarations in a pass following the initial parsing of
a program, we incorporate the logic directly into the parser. This lays
the groundwork for further optimisations (such as improving performance in
declaration expressions -- var x = y; -- to match that of standard assignment)
in addition to providing a 0.4% performance improvement in SunSpider.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/kjs/Parser.h

    r28604 r28854  
    2929#include <wtf/Noncopyable.h>
    3030#include <wtf/OwnPtr.h>
     31#include <wtf/RefPtr.h>
    3132#include "nodes.h"
    3233
     
    3839
    3940    struct UChar;
     41
     42    template <typename T> struct ParserRefCountedData : ParserRefCounted {
     43        T data;
     44    };
    4045
    4146    class Parser : Noncopyable {
     
    4954        int sourceId() const { return m_sourceId; }
    5055
    51         void didFinishParsing(SourceElements* sourceElements, int lastLine)
     56        void didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
     57                              ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, int lastLine)
    5258        {
    5359            m_sourceElements.set(sourceElements);
     60            m_varDeclarations = varStack;
     61            m_funcDeclarations = funcStack;
    5462            m_lastLine = lastLine;
    5563        }
     
    6573        int m_sourceId;
    6674        OwnPtr<SourceElements> m_sourceElements;
     75        RefPtr<ParserRefCountedData<DeclarationStacks::VarStack> > m_varDeclarations;
     76        RefPtr<ParserRefCountedData<DeclarationStacks::FunctionStack> > m_funcDeclarations;
    6777        int m_lastLine;
    6878    };
     
    8191            return 0;
    8292        }
    83         RefPtr<ParsedNode> node = new ParsedNode(m_sourceElements.release());
     93        RefPtr<ParsedNode> node = new ParsedNode(m_sourceElements.release(),
     94                                                 m_varDeclarations ? &m_varDeclarations->data : 0,
     95                                                 m_funcDeclarations ? &m_funcDeclarations->data : 0);
     96        m_varDeclarations = 0;
     97        m_funcDeclarations = 0;
    8498        m_sourceURL = UString();
    8599        node->setLoc(startingLineNumber, m_lastLine);
Note: See TracChangeset for help on using the changeset viewer.