]> granicus.if.org Git - clang/commitdiff
Reduce string duplication
authorAlp Toker <alp@nuanti.com>
Tue, 20 May 2014 22:03:47 +0000 (22:03 +0000)
committerAlp Toker <alp@nuanti.com>
Tue, 20 May 2014 22:03:47 +0000 (22:03 +0000)
If we're so keen on saving a dynamic allocation to add the trailing space, we
might as well do it in style.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209247 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaDecl.cpp

index 44ca495cb152d3a275c13df863775a638f608025..d65ba117dc8db04bef3f3e0bbf85723724c5d5f6 100644 (file)
@@ -513,35 +513,30 @@ static bool isTagTypeWithMissingTag(Sema &SemaRef, LookupResult &Result,
   LookupResult R(SemaRef, Name, NameLoc, Sema::LookupTagName);
   SemaRef.LookupParsedName(R, S, &SS);
   if (TagDecl *Tag = R.getAsSingle<TagDecl>()) {
-    const char *TagName = 0;
-    const char *FixItTagName = 0;
+    StringRef FixItTagName;
     switch (Tag->getTagKind()) {
       case TTK_Class:
-        TagName = "class";
         FixItTagName = "class ";
         break;
 
       case TTK_Enum:
-        TagName = "enum";
         FixItTagName = "enum ";
         break;
 
       case TTK_Struct:
-        TagName = "struct";
         FixItTagName = "struct ";
         break;
 
       case TTK_Interface:
-        TagName = "__interface";
         FixItTagName = "__interface ";
         break;
 
       case TTK_Union:
-        TagName = "union";
         FixItTagName = "union ";
         break;
     }
 
+    StringRef TagName = FixItTagName.drop_back();
     SemaRef.Diag(NameLoc, diag::err_use_of_tag_name_without_tag)
       << Name << TagName << SemaRef.getLangOpts().CPlusPlus
       << FixItHint::CreateInsertion(NameLoc, FixItTagName);