Make BuiltinType::getName return a StringRef and introduce BuiltinType::getNameAsCString

to get a const char* if necessary.

This avoids unnecessary conversions when we want to use the result of getName as
a StringRef.

Part of rdar://10796159

llvm-svn: 156227
This commit is contained in:
Argyrios Kyrtzidis
2012-05-05 04:20:28 +00:00
parent de9e92ed9b
commit bbff3da622
5 changed files with 11 additions and 5 deletions

View File

@@ -1757,7 +1757,13 @@ public:
}
Kind getKind() const { return static_cast<Kind>(BuiltinTypeBits.Kind); }
const char *getName(const PrintingPolicy &Policy) const;
StringRef getName(const PrintingPolicy &Policy) const;
const char *getNameAsCString(const PrintingPolicy &Policy) const {
// The StringRef is null-terminated.
StringRef str = getName(Policy);
assert(!str.empty() && str.data()[str.size()] == '\0');
return str.data();
}
bool isSugared() const { return false; }
QualType desugar() const { return QualType(this, 0); }

View File

@@ -1425,7 +1425,7 @@ const char *Type::getTypeClassName() const {
llvm_unreachable("Invalid type class.");
}
const char *BuiltinType::getName(const PrintingPolicy &Policy) const {
StringRef BuiltinType::getName(const PrintingPolicy &Policy) const {
switch (getKind()) {
case Void: return "void";
case Bool: return Policy.Bool ? "bool" : "_Bool";

View File

@@ -210,7 +210,7 @@ void TypePrinter::printBuiltin(const BuiltinType *T, std::string &S) {
} else {
// Prefix the basic type, e.g. 'int X'.
S = ' ' + S;
S = T->getName(Policy) + S;
S = T->getNameAsCString(Policy) + S;
}
}

View File

@@ -335,7 +335,7 @@ void CGDebugInfo::CreateCompileUnit() {
/// one if necessary.
llvm::DIType CGDebugInfo::CreateType(const BuiltinType *BT) {
unsigned Encoding = 0;
const char *BTName = NULL;
StringRef BTName;
switch (BT->getKind()) {
#define BUILTIN_TYPE(Id, SingletonId)
#define PLACEHOLDER_TYPE(Id, SingletonId) \

View File

@@ -1414,7 +1414,7 @@ static const char *GetCompletionTypeString(QualType T,
if (!T.getLocalQualifiers()) {
// Built-in type names are constant strings.
if (const BuiltinType *BT = dyn_cast<BuiltinType>(T))
return BT->getName(Policy);
return BT->getNameAsCString(Policy);
// Anonymous tag types are constant strings.
if (const TagType *TagT = dyn_cast<TagType>(T))