[llvm-branch-commits] [cfe-branch] r119420 - /cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp
Daniel Dunbar
daniel at zuster.org
Tue Nov 16 16:23:45 PST 2010
Author: ddunbar
Date: Tue Nov 16 18:23:45 2010
New Revision: 119420
URL: http://llvm.org/viewvc/llvm-project?rev=119420&view=rev
Log:
Merge r119338:
--
Author: Ted Kremenek <kremenek at apple.com>
Date: Tue Nov 16 08:15:38 2010 +0000
Rework USR generation from CXCursors to use CXStringBufs
for the backing of generated USRs. This optmizes
for the case when a client generates a sequence
of USRs in sequence, disposing of them soon
after generating them. By using a string buffer,
we recycle malloc'ed memory instead of constantly
malloc'ing and copying strings.
Modified:
cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp
Modified: cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp?rev=119420&r1=119419&r2=119420&view=diff
==============================================================================
--- cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp (original)
+++ cfe/branches/Apple/whitney/tools/libclang/CIndexUSRs.cpp Tue Nov 16 18:23:45 2010
@@ -30,7 +30,8 @@
namespace {
class USRGenerator : public DeclVisitor<USRGenerator> {
- llvm::SmallString<1024> Buf;
+ llvm::OwningPtr<llvm::SmallString<128> > OwnedBuf;
+ llvm::SmallVectorImpl<char> &Buf;
llvm::raw_svector_ostream Out;
bool IgnoreResults;
ASTUnit *AU;
@@ -39,11 +40,13 @@
llvm::DenseMap<const Type *, unsigned> TypeSubstitutions;
public:
- USRGenerator(const CXCursor *C = 0)
- : Out(Buf),
- IgnoreResults(false),
- AU(C ? cxcursor::getCursorASTUnit(*C) : 0),
- generatedLoc(false)
+ USRGenerator(const CXCursor *C = 0, llvm::SmallVectorImpl<char> *extBuf = 0)
+ : OwnedBuf(extBuf ? 0 : new llvm::SmallString<128>()),
+ Buf(extBuf ? *extBuf : *OwnedBuf.get()),
+ Out(Buf),
+ IgnoreResults(false),
+ AU(C ? cxcursor::getCursorASTUnit(*C) : 0),
+ generatedLoc(false)
{
// Add the USR space prefix.
Out << "c:";
@@ -794,19 +797,27 @@
break;
}
- USRGenerator UG(&C);
- UG->Visit(D);
-
- if (UG->ignoreResults())
+ CXTranslationUnit TU = cxcursor::getCursorTU(C);
+ if (!TU)
return createCXString("");
-#if 0
- // For development testing.
- assert(UG.str().size() > 2);
-#endif
+ CXStringBuf *buf = cxstring::getCXStringBuf(TU);
+ if (!buf)
+ return createCXString("");
+
+ {
+ USRGenerator UG(&C, &buf->Data);
+ UG->Visit(D);
- // Return a copy of the string that must be disposed by the caller.
- return createCXString(UG.str(), true);
+ if (UG->ignoreResults()) {
+ disposeCXStringBuf(buf);
+ return createCXString("");
+ }
+ }
+ // Return the C-string, but don't make a copy since it is already in
+ // the string buffer.
+ buf->Data.push_back('\0');
+ return createCXString(buf);
}
extern "C" {
@@ -818,10 +829,21 @@
return getDeclCursorUSR(C);
if (K == CXCursor_MacroDefinition) {
- USRGenerator UG(&C);
- UG << "macro@"
- << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
- return createCXString(UG.str(), true);
+ CXTranslationUnit TU = cxcursor::getCursorTU(C);
+ if (!TU)
+ return createCXString("");
+
+ CXStringBuf *buf = cxstring::getCXStringBuf(TU);
+ if (!buf)
+ return createCXString("");
+
+ {
+ USRGenerator UG(&C, &buf->Data);
+ UG << "macro@"
+ << cxcursor::getCursorMacroDefinition(C)->getName()->getNameStart();
+ }
+ buf->Data.push_back('\0');
+ return createCXString(buf);
}
return createCXString("");
More information about the llvm-branch-commits
mailing list