[cfe-commits] r119290 - /cfe/trunk/tools/libclang/CIndex.cpp
Ted Kremenek
kremenek at apple.com
Mon Nov 15 15:31:32 PST 2010
Author: kremenek
Date: Mon Nov 15 17:31:32 2010
New Revision: 119290
URL: http://llvm.org/viewvc/llvm-project?rev=119290&view=rev
Log:
CursorVisitor: cache worklists created for data-recursion to reduce malloc() traffic.
Modified:
cfe/trunk/tools/libclang/CIndex.cpp
Modified: cfe/trunk/tools/libclang/CIndex.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/libclang/CIndex.cpp?rev=119290&r1=119289&r2=119290&view=diff
==============================================================================
--- cfe/trunk/tools/libclang/CIndex.cpp (original)
+++ cfe/trunk/tools/libclang/CIndex.cpp Mon Nov 15 17:31:32 2010
@@ -177,6 +177,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;
@@ -223,6 +227,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 TU; }
bool Visit(CXCursor Cursor, bool CheckedRegionOfInterest = false);
@@ -2019,9 +2031,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 cfe-commits
mailing list