source: webkit/trunk/JavaScriptCore/parser/Parser.cpp@ 43313

Last change on this file since 43313 was 43259, checked in by Darin Adler, 16 years ago

2009-05-05 Darin Adler <Darin Adler>

Reviewed by Sam Weinig.

Bug 25569: make ParserRefCounted use conventional reference counting
https://bugs.webkit.org/show_bug.cgi?id=25569

SunSpider speedup of about 1.6%.

  • parser/Nodes.cpp: (JSC::NodeReleaser::releaseAllNodes): ALWAYS_INLINE. (JSC::NodeReleaser::adopt): Ditto. (JSC::ParserRefCounted::ParserRefCounted): Removed most of the code. Add the object to a Vector<RefPtr> that gets cleared after parsing. (JSC::ParserRefCounted::~ParserRefCounted): Removed most of the code.
  • parser/Nodes.h: Made ParserRefCounted inherit from RefCounted and made inline versions of the constructor and destructor. Made the Node constructor inline.
  • parser/Parser.cpp: (JSC::Parser::parse): Call globalData->parserObjects.shrink(0) after parsing, where it used to call ParserRefCounted::deleteNewObjects.
  • runtime/JSGlobalData.cpp: (JSC::JSGlobalData::JSGlobalData): Eliminated code to manage the newParserObjects and parserObjectExtraRefCounts. (JSC::JSGlobalData::~JSGlobalData): Ditto.
  • runtime/JSGlobalData.h: Replaced the HashSet and HashCountedSet with a Vector.
  • wtf/PassRefPtr.h: (WTF::PassRefPtr::~PassRefPtr): The most common thing to do with a PassRefPtr in hot code is to pass it and then destroy it once it's set to zero. Help the optimizer by telling it that's true.
  • Property svn:eol-style set to native
File size: 3.4 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "Parser.h"
25
26#include "Debugger.h"
27#include "Lexer.h"
28#include <wtf/HashSet.h>
29#include <wtf/Vector.h>
30#include <memory>
31
32using std::auto_ptr;
33
34#ifndef yyparse
35extern int jscyyparse(void*);
36#endif
37
38namespace JSC {
39
40void Parser::parse(JSGlobalData* globalData, int* errLine, UString* errMsg)
41{
42 ASSERT(!m_sourceElements);
43
44 int defaultErrLine;
45 UString defaultErrMsg;
46
47 if (!errLine)
48 errLine = &defaultErrLine;
49 if (!errMsg)
50 errMsg = &defaultErrMsg;
51
52 *errLine = -1;
53 *errMsg = 0;
54
55 Lexer& lexer = *globalData->lexer;
56 lexer.setCode(*m_source);
57
58 int parseError = jscyyparse(globalData);
59 bool lexError = lexer.sawError();
60 int lineNumber = lexer.lineNumber();
61 lexer.clear();
62
63 globalData->parserObjects.shrink(0);
64
65 if (parseError || lexError) {
66 *errLine = lineNumber;
67 *errMsg = "Parse error";
68 m_sourceElements.clear();
69 }
70}
71
72void Parser::reparseInPlace(JSGlobalData* globalData, FunctionBodyNode* functionBodyNode)
73{
74 ASSERT(!functionBodyNode->data());
75
76 m_source = &functionBodyNode->source();
77 globalData->lexer->setIsReparsing();
78 parse(globalData, 0, 0);
79 ASSERT(m_sourceElements);
80
81 functionBodyNode->adoptData(std::auto_ptr<ScopeNodeData>(new ScopeNodeData(m_sourceElements.get(),
82 m_varDeclarations ? &m_varDeclarations->data : 0,
83 m_funcDeclarations ? &m_funcDeclarations->data : 0,
84 m_numConstants)));
85 bool usesArguments = functionBodyNode->usesArguments();
86 functionBodyNode->setFeatures(m_features);
87 if (usesArguments && !functionBodyNode->usesArguments())
88 functionBodyNode->setUsesArguments();
89
90 m_source = 0;
91 m_sourceElements = 0;
92 m_varDeclarations = 0;
93 m_funcDeclarations = 0;
94}
95
96void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
97 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, CodeFeatures features, int lastLine, int numConstants)
98{
99 m_sourceElements = sourceElements;
100 m_varDeclarations = varStack;
101 m_funcDeclarations = funcStack;
102 m_features = features;
103 m_lastLine = lastLine;
104 m_numConstants = numConstants;
105}
106
107} // namespace JSC
Note: See TracBrowser for help on using the repository browser.