r275697 - CodeGen: use StringRefs more in ObjC class generation, NFC
Saleem Abdulrasool via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 16 15:42:06 PDT 2016
Author: compnerd
Date: Sat Jul 16 17:42:06 2016
New Revision: 275697
URL: http://llvm.org/viewvc/llvm-project?rev=275697&view=rev
Log:
CodeGen: use StringRefs more in ObjC class generation, NFC
Rather than building up a number of SmallString-s in order to construct a
std::string, use more StringRefs and construct the string once before use. This
avoids unnecessary string constructions. NFC.
Modified:
cfe/trunk/lib/CodeGen/CGObjCMac.cpp
Modified: cfe/trunk/lib/CodeGen/CGObjCMac.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGObjCMac.cpp?rev=275697&r1=275696&r2=275697&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGObjCMac.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGObjCMac.cpp Sat Jul 16 17:42:06 2016
@@ -5978,7 +5978,6 @@ void CGObjCNonFragileABIMac::GetClassSiz
}
void CGObjCNonFragileABIMac::GenerateClass(const ObjCImplementationDecl *ID) {
- std::string ClassName = ID->getObjCRuntimeNameAsString();
if (!ObjCEmptyCacheVar) {
ObjCEmptyCacheVar = new llvm::GlobalVariable(
CGM.getModule(), ObjCTypes.CacheTy, false,
@@ -5997,12 +5996,10 @@ void CGObjCNonFragileABIMac::GenerateCla
CGM.getDataLayout().getTypeAllocSize(ObjCTypes.ClassnfABITy);
uint32_t InstanceSize = InstanceStart;
uint32_t flags = NonFragileABI_Class_Meta;
- llvm::SmallString<64> ObjCMetaClassName(getMetaclassSymbolPrefix());
- llvm::SmallString<64> ObjCClassName(getClassSymbolPrefix());
- llvm::SmallString<64> TClassName;
llvm::GlobalVariable *SuperClassGV, *IsAGV;
+ StringRef ClassName = ID->getObjCRuntimeNameAsString();
const auto *CI = ID->getClassInterface();
assert(CI && "CGObjCNonFragileABIMac::GenerateClass - class is 0");
@@ -6023,13 +6020,11 @@ void CGObjCNonFragileABIMac::GenerateCla
// class is root
flags |= NonFragileABI_Class_Root;
- TClassName = ObjCClassName;
- TClassName += ClassName;
- SuperClassGV = GetClassGlobal(TClassName.str(), CI->isWeakImported());
-
- TClassName = ObjCMetaClassName;
- TClassName += ClassName;
- IsAGV = GetClassGlobal(TClassName.str(), CI->isWeakImported());
+ SuperClassGV = GetClassGlobal((getClassSymbolPrefix() + ClassName).str(),
+ CI->isWeakImported());
+
+ IsAGV = GetClassGlobal((getMetaclassSymbolPrefix() + ClassName).str(),
+ CI->isWeakImported());
} else {
// Has a root. Current class is not a root.
const ObjCInterfaceDecl *Root = ID->getClassInterface();
@@ -6037,25 +6032,25 @@ void CGObjCNonFragileABIMac::GenerateCla
Root = Super;
const auto *Super = CI->getSuperClass();
+ StringRef RootClassName = Root->getObjCRuntimeNameAsString();
+ StringRef SuperClassName = Super->getObjCRuntimeNameAsString();
- TClassName = ObjCMetaClassName ;
- TClassName += Root->getObjCRuntimeNameAsString();
- IsAGV = GetClassGlobal(TClassName.str(), Root->isWeakImported());
+ IsAGV = GetClassGlobal((getMetaclassSymbolPrefix() + RootClassName).str(),
+ Root->isWeakImported());
// work on super class metadata symbol.
- TClassName = ObjCMetaClassName;
- TClassName += Super->getObjCRuntimeNameAsString();
- SuperClassGV = GetClassGlobal(TClassName.str(), Super->isWeakImported());
+ SuperClassGV =
+ GetClassGlobal((getMetaclassSymbolPrefix() + SuperClassName).str(),
+ Super->isWeakImported());
}
llvm::GlobalVariable *CLASS_RO_GV =
BuildClassRoTInitializer(flags, InstanceStart, InstanceSize, ID);
- TClassName = ObjCMetaClassName;
- TClassName += ClassName;
llvm::GlobalVariable *MetaTClass =
- BuildClassMetaData(TClassName.str(), IsAGV, SuperClassGV, CLASS_RO_GV,
- classIsHidden, CI->isWeakImported());
+ BuildClassMetaData((getMetaclassSymbolPrefix() + ClassName).str(), IsAGV,
+ SuperClassGV, CLASS_RO_GV, classIsHidden,
+ CI->isWeakImported());
DefinedMetaClasses.push_back(MetaTClass);
// Metadata for the class
@@ -6085,21 +6080,21 @@ void CGObjCNonFragileABIMac::GenerateCla
} else {
// Has a root. Current class is not a root.
const auto *Super = CI->getSuperClass();
+ StringRef SuperClassName = Super->getObjCRuntimeNameAsString();
- TClassName = ObjCClassName;
- TClassName += Super->getObjCRuntimeNameAsString();
- SuperClassGV = GetClassGlobal(TClassName.str(), Super->isWeakImported());
+ SuperClassGV =
+ GetClassGlobal((getClassSymbolPrefix() + SuperClassName).str(),
+ Super->isWeakImported());
}
GetClassSizeInfo(ID, InstanceStart, InstanceSize);
CLASS_RO_GV =
BuildClassRoTInitializer(flags, InstanceStart, InstanceSize, ID);
- TClassName = ObjCClassName;
- TClassName += ClassName;
llvm::GlobalVariable *ClassMD =
- BuildClassMetaData(TClassName.str(), MetaTClass, SuperClassGV, CLASS_RO_GV,
- classIsHidden, CI->isWeakImported());
+ BuildClassMetaData((getClassSymbolPrefix() + ClassName).str(), MetaTClass,
+ SuperClassGV, CLASS_RO_GV, classIsHidden,
+ CI->isWeakImported());
DefinedClasses.push_back(ClassMD);
ImplementedClasses.push_back(CI);
More information about the cfe-commits
mailing list