aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2007-07-15 00:04:39 +0000
committerChris Lattner <sabre@nondot.org>2007-07-15 00:04:39 +0000
commit9e344c65b1e8b83e1d3ada507cf653526ff2c005 (patch)
treef340c6f0802d6b879357108cb66c2f0de6deb46a
parent25c9648909193d380a4e135d2e3d25394ba12922 (diff)
Make parser scope cache be a member of the parser instead of a global,
which makes it multithread clean. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@39863 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--Parse/Parser.cpp27
-rw-r--r--include/clang/Parse/Parser.h5
2 files changed, 15 insertions, 17 deletions
diff --git a/Parse/Parser.cpp b/Parse/Parser.cpp
index 251febbcd6..bc7bd99782 100644
--- a/Parse/Parser.cpp
+++ b/Parse/Parser.cpp
@@ -20,7 +20,7 @@ Parser::Parser(Preprocessor &pp, Action &actions)
: PP(pp), Actions(actions), Diags(PP.getDiagnostics()) {
Tok.setKind(tok::eof);
CurScope = 0;
-
+ NumCachedScopes = 0;
ParenCount = BracketCount = BraceCount = 0;
}
@@ -172,15 +172,10 @@ bool Parser::SkipUntil(const tok::TokenKind *Toks, unsigned NumToks,
// Scope manipulation
//===----------------------------------------------------------------------===//
-/// ScopeCache - Cache scopes to avoid malloc traffic.
-/// FIXME: eliminate this static ctor
-static llvm::SmallVector<Scope*, 16> ScopeCache;
-
/// EnterScope - Start a new scope.
void Parser::EnterScope(unsigned ScopeFlags) {
- if (!ScopeCache.empty()) {
- Scope *N = ScopeCache.back();
- ScopeCache.pop_back();
+ if (NumCachedScopes) {
+ Scope *N = ScopeCache[--NumCachedScopes];
N->Init(CurScope, ScopeFlags);
CurScope = N;
} else {
@@ -195,13 +190,13 @@ void Parser::ExitScope() {
// Inform the actions module that this scope is going away.
Actions.PopScope(Tok.getLocation(), CurScope);
- Scope *Old = CurScope;
- CurScope = Old->getParent();
+ Scope *OldScope = CurScope;
+ CurScope = OldScope->getParent();
- if (ScopeCache.size() == 16)
- delete Old;
+ if (NumCachedScopes == ScopeCacheSize)
+ delete OldScope;
else
- ScopeCache.push_back(Old);
+ ScopeCache[NumCachedScopes++] = OldScope;
}
@@ -216,10 +211,8 @@ Parser::~Parser() {
delete CurScope;
// Free the scope cache.
- while (!ScopeCache.empty()) {
- delete ScopeCache.back();
- ScopeCache.pop_back();
- }
+ for (unsigned i = 0, e = NumCachedScopes; i != e; ++i)
+ delete ScopeCache[i];
}
/// Initialize - Warm up the parser.
diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h
index 19bee276a4..bb3022ed41 100644
--- a/include/clang/Parse/Parser.h
+++ b/include/clang/Parse/Parser.h
@@ -43,6 +43,11 @@ class Parser {
Scope *CurScope;
Diagnostic &Diags;
+
+ /// ScopeCache - Cache scopes to reduce malloc traffic.
+ enum { ScopeCacheSize = 16 };
+ unsigned NumCachedScopes;
+ Scope *ScopeCache[ScopeCacheSize];
public:
Parser(Preprocessor &PP, Action &Actions);
~Parser();