mirror of
https://github.com/intel/llvm.git
synced 2026-02-01 17:07:36 +08:00
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:
@@ -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); }
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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) \
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user