[llvm-branch-commits] [cfe-branch] r119650 - /cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
Daniel Dunbar
daniel at zuster.org
Wed Nov 17 18:37:32 PST 2010
Author: ddunbar
Date: Wed Nov 17 20:37:32 2010
New Revision: 119650
URL: http://llvm.org/viewvc/llvm-project?rev=119650&view=rev
Log:
Merge r119290:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Mon Nov 15 23:31:32 2010 +0000
CursorVisitor: cache worklists created for data-recursion to reduce malloc() traffic.
Modified:
cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp?rev=119650&r1=119649&r2=119650&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndex.cpp Wed Nov 17 20:37:32 2010
@@ -188,6 +188,10 @@
DeclContext::decl_iterator *DI_current;
DeclContext::decl_iterator DE_current;
+ // Cache of pre-allocated worklists for data-recursion walk of Stmts.
+ llvm::SmallVector<VisitorWorkList*, 5> WorkListFreeList;
+ llvm::SmallVector<VisitorWorkList*, 5> WorkListCache;
+
using DeclVisitor<CursorVisitor, bool>::Visit;
using TypeLocVisitor<CursorVisitor, bool>::Visit;
using StmtVisitor<CursorVisitor, bool>::Visit;
@@ -236,6 +240,14 @@
StmtParent = 0;
}
+ ~CursorVisitor() {
+ // Free the pre-allocated worklists for data-recursion.
+ for (llvm::SmallVectorImpl<VisitorWorkList*>::iterator
+ I = WorkListCache.begin(), E = WorkListCache.end(); I != E; ++I) {
+ delete *I;
+ }
+ }
+
ASTUnit *getASTUnit() const { return static_cast<ASTUnit*>(TU->TUData); }
CXTranslationUnit getTU() const { return TU; }
@@ -2034,9 +2046,20 @@
}
bool CursorVisitor::VisitDataRecursive(Stmt *S) {
- VisitorWorkList WL;
- EnqueueWorkList(WL, S);
- return RunVisitorWorkList(WL);
+ VisitorWorkList *WL = 0;
+ if (!WorkListFreeList.empty()) {
+ WL = WorkListFreeList.back();
+ WL->clear();
+ WorkListFreeList.pop_back();
+ }
+ else {
+ WL = new VisitorWorkList();
+ WorkListCache.push_back(WL);
+ }
+ EnqueueWorkList(*WL, S);
+ bool result = RunVisitorWorkList(*WL);
+ WorkListFreeList.push_back(WL);
+ return result;
}
//===----------------------------------------------------------------------===//
More information about the llvm-branch-commits
mailing list