source: webkit/trunk/JavaScriptCore/kjs/Parser.cpp@ 31936

Last change on this file since 31936 was 31936, checked in by [email protected], 17 years ago

Reviewed by Darin.

Implement an abstraction for thread-specific storage, use it to get rid of some static objects.

SunSpider results were not conclusive, possibly up to 0.2% slowdown.

  • wtf/ThreadSpecific.h: Added. (WTF::::ThreadSpecific): (WTF::::~ThreadSpecific): (WTF::::get): (WTF::::set): (WTF::::destroy): (WTF::T): (WTF::::operator): Only implemented for platforms that use pthreads.
  • kjs/CommonIdentifiers.cpp: (KJS::CommonIdentifiers::shared):
  • kjs/CommonIdentifiers.h:
  • kjs/InitializeThreading.cpp: (KJS::initializeThreading):
  • kjs/Parser.cpp: (KJS::parser):
  • kjs/Parser.h:
  • kjs/identifier.cpp: (KJS::identifierTable): (KJS::literalIdentifierTable): (KJS::Identifier::initializeIdentifierThreading):
  • kjs/identifier.h:
  • kjs/lexer.cpp: (KJS::lexer):
  • kjs/lexer.h: Make static instances per-thread.
  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1// -*- c-basic-offset: 4 -*-
2/*
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten ([email protected])
5 * Copyright (C) 2001 Peter Kelly ([email protected])
6 * Copyright (C) 2003, 2006, 2007 Apple Inc.
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Library General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Library General Public License for more details.
17 *
18 * You should have received a copy of the GNU Library General Public License
19 * along with this library; see the file COPYING.LIB. If not, write to
20 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 * Boston, MA 02110-1301, USA.
22 *
23 */
24
25#include "config.h"
26#include "Parser.h"
27
28#include "lexer.h"
29#include <wtf/HashSet.h>
30#if USE(MULTIPLE_THREADS)
31#include <wtf/ThreadSpecific.h>
32#endif
33#include <wtf/Vector.h>
34
35extern int kjsyyparse(void*);
36
37namespace KJS {
38
39Parser::Parser()
40 : m_sourceId(0)
41{
42}
43
44void Parser::parse(int startingLineNumber,
45 const UChar* code, unsigned length,
46 int* sourceId, int* errLine, UString* errMsg)
47{
48 ASSERT(!m_sourceElements);
49
50 if (errLine)
51 *errLine = -1;
52 if (errMsg)
53 *errMsg = 0;
54
55 Lexer& lexer = KJS::lexer();
56
57 lexer.setCode(startingLineNumber, code, length);
58 m_sourceId++;
59 if (sourceId)
60 *sourceId = m_sourceId;
61
62 int parseError = kjsyyparse(&lexer);
63 bool lexError = lexer.sawError();
64 lexer.clear();
65
66 ParserRefCounted::deleteNewObjects();
67
68 if (parseError || lexError) {
69 if (errLine)
70 *errLine = lexer.lineNo();
71 if (errMsg)
72 *errMsg = "Parse error";
73 m_sourceElements.clear();
74 }
75}
76
77void Parser::didFinishParsing(SourceElements* sourceElements, ParserRefCountedData<DeclarationStacks::VarStack>* varStack,
78 ParserRefCountedData<DeclarationStacks::FunctionStack>* funcStack, bool usesEval, bool needsClosure, int lastLine)
79{
80 m_sourceElements = sourceElements ? sourceElements : new SourceElements;
81 m_varDeclarations = varStack;
82 m_funcDeclarations = funcStack;
83 m_usesEval = usesEval;
84 m_needsClosure = needsClosure;
85 m_lastLine = lastLine;
86}
87
88Parser& parser()
89{
90#if USE(MULTIPLE_THREADS)
91 static ThreadSpecific<Parser> staticParser;
92 return *staticParser;
93#else
94 static Parser staticParser;
95 return staticParser;
96#endif
97}
98
99} // namespace KJS
Note: See TracBrowser for help on using the repository browser.