From 2348c6268a84a55445af73cc6fe26136b2b4dc87 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Fri, 12 Nov 2010 18:45:23 +0000 Subject: [PATCH] Reduce string thrashing. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@118915 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CodeGenTypes.cpp | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/lib/CodeGen/CodeGenTypes.cpp b/lib/CodeGen/CodeGenTypes.cpp index 87cab311d4..84c1ceb1ff 100644 --- a/lib/CodeGen/CodeGenTypes.cpp +++ b/lib/CodeGen/CodeGenTypes.cpp @@ -371,26 +371,31 @@ const llvm::Type *CodeGenTypes::ConvertNewType(QualType T) { const TagDecl *TD = cast(Ty).getDecl(); const llvm::Type *Res = ConvertTagDeclType(TD); - std::string TypeName(TD->getKindName()); - TypeName += '.'; + llvm::SmallString<256> TypeName; + llvm::raw_svector_ostream OS(TypeName); + OS << TD->getKindName() << '.'; // Name the codegen type after the typedef name // if there is no tag type name available - if (TD->getIdentifier()) + if (TD->getIdentifier()) { // FIXME: We should not have to check for a null decl context here. // Right now we do it because the implicit Obj-C decls don't have one. - TypeName += TD->getDeclContext() ? TD->getQualifiedNameAsString() : - TD->getNameAsString(); - else if (const TypedefType *TdT = dyn_cast(T)) + if (TD->getDeclContext()) + OS << TD->getQualifiedNameAsString(); + else + TD->printName(OS); + } else if (const TypedefType *TdT = dyn_cast(T)) { // FIXME: We should not have to check for a null decl context here. // Right now we do it because the implicit Obj-C decls don't have one. - TypeName += TdT->getDecl()->getDeclContext() ? - TdT->getDecl()->getQualifiedNameAsString() : - TdT->getDecl()->getNameAsString(); - else - TypeName += "anon"; + if (TdT->getDecl()->getDeclContext()) + OS << TdT->getDecl()->getQualifiedNameAsString(); + else + TdT->getDecl()->printName(OS); + } else { + OS << "anon"; + } - TheModule.addTypeName(TypeName, Res); + TheModule.addTypeName(OS.str(), Res); return Res; }