From c6b468e46d467eb8d0bcfdbbcc776ef9650133a0 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 13 Apr 2012 18:00:37 +0000 Subject: [PATCH] Avoid string thrashing when we can concatenate them in the final buffer. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@154678 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 7301d2060b..d286d24715 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/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(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(Buffer.length()); - memcpy(StrPtr, Buffer.data(), Buffer.length()); - return StringRef(StrPtr, Buffer.length()); + size_t Length = Name.size() + TemplateArgList.size(); + char *StrPtr = DebugInfoNames.Allocate(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. -- 2.40.0