summaryrefslogtreecommitdiffstats
path: root/clang/lib/CodeGen
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-04-13 18:00:37 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-04-13 18:00:37 +0000
commit6d3f11142de7f1163f7a94720c75557355844c21 (patch)
treeed3691bb86001da87af55cb3c204d92bf2ac2d59 /clang/lib/CodeGen
parentcf6ce28f710a12fe1dfb1468c1e2331654a2c5e8 (diff)
downloadbcm5719-llvm-6d3f11142de7f1163f7a94720c75557355844c21.tar.gz
bcm5719-llvm-6d3f11142de7f1163f7a94720c75557355844c21.zip
Avoid string thrashing when we can concatenate them in the final buffer.
llvm-svn: 154678
Diffstat (limited to 'clang/lib/CodeGen')
-rw-r--r--clang/lib/CodeGen/CGDebugInfo.cpp16
1 files changed, 8 insertions, 8 deletions
diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp
index 7301d2060ba..d286d24715e 100644
--- a/clang/lib/CodeGen/CGDebugInfo.cpp
+++ b/clang/lib/CodeGen/CGDebugInfo.cpp
@@ -184,7 +184,6 @@ CGDebugInfo::getClassName(const RecordDecl *RD) {
const TemplateArgument *Args;
unsigned NumArgs;
- std::string Buffer;
if (TypeSourceInfo *TAW = Spec->getTypeAsWritten()) {
const TemplateSpecializationType *TST =
cast<TemplateSpecializationType>(TAW->getType());
@@ -195,16 +194,17 @@ CGDebugInfo::getClassName(const RecordDecl *RD) {
Args = TemplateArgs.data();
NumArgs = TemplateArgs.size();
}
- Buffer = RD->getIdentifier()->getNameStart();
+ StringRef Name = RD->getIdentifier()->getName();
PrintingPolicy Policy(CGM.getLangOpts());
- Buffer += TemplateSpecializationType::PrintTemplateArgumentList(Args,
- NumArgs,
- Policy);
+ std::string TemplateArgList =
+ TemplateSpecializationType::PrintTemplateArgumentList(Args, NumArgs, Policy);
// Copy this name on the side and use its reference.
- char *StrPtr = DebugInfoNames.Allocate<char>(Buffer.length());
- memcpy(StrPtr, Buffer.data(), Buffer.length());
- return StringRef(StrPtr, Buffer.length());
+ size_t Length = Name.size() + TemplateArgList.size();
+ char *StrPtr = DebugInfoNames.Allocate<char>(Length);
+ memcpy(StrPtr, Name.data(), Name.size());
+ memcpy(StrPtr + Name.size(), TemplateArgList.data(), TemplateArgList.size());
+ return StringRef(StrPtr, Length);
}
/// getOrCreateFile - Get the file debug info descriptor for the input location.
OpenPOWER on IntegriCloud