[cfe-commits] r39863 - in /cfe/trunk: Parse/Parser.cpp include/clang/Parse/Parser.h
Chris Lattner
sabre at nondot.org
Sat Jul 14 17:04:39 PDT 2007
Author: lattner
Date: Sat Jul 14 19:04:39 2007
New Revision: 39863
URL: http://llvm.org/viewvc/llvm-project?rev=39863&view=rev
Log:
Make parser scope cache be a member of the parser instead of a global,
which makes it multithread clean.
Modified:
cfe/trunk/Parse/Parser.cpp
cfe/trunk/include/clang/Parse/Parser.h
Modified: cfe/trunk/Parse/Parser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Parse/Parser.cpp?rev=39863&r1=39862&r2=39863&view=diff
==============================================================================
--- cfe/trunk/Parse/Parser.cpp (original)
+++ cfe/trunk/Parse/Parser.cpp Sat Jul 14 19:04:39 2007
@@ -20,7 +20,7 @@
: PP(pp), Actions(actions), Diags(PP.getDiagnostics()) {
Tok.setKind(tok::eof);
CurScope = 0;
-
+ NumCachedScopes = 0;
ParenCount = BracketCount = BraceCount = 0;
}
@@ -172,15 +172,10 @@
// 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 @@
// 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 @@
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.
Modified: cfe/trunk/include/clang/Parse/Parser.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Parse/Parser.h?rev=39863&r1=39862&r2=39863&view=diff
==============================================================================
--- cfe/trunk/include/clang/Parse/Parser.h (original)
+++ cfe/trunk/include/clang/Parse/Parser.h Sat Jul 14 19:04:39 2007
@@ -43,6 +43,11 @@
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();
More information about the cfe-commits
mailing list