mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-13 07:00:59 +00:00
add new isSingleStringRef()/getSingleStringRef() methods to twine,
and use them to avoid a copy of a string in getNameWithPrefix in the common case. It seems like Value::setName and other places should use this as well? llvm-svn: 93301
This commit is contained in:
parent
951cfb6b8b
commit
9c1ca33ac3
@ -329,6 +329,22 @@ namespace llvm {
|
|||||||
bool isTriviallyEmpty() const {
|
bool isTriviallyEmpty() const {
|
||||||
return isNullary();
|
return isNullary();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// isSingleStringRef - Return true if this twine can be dynamically
|
||||||
|
/// accessed as a single StringRef value with getSingleStringRef().
|
||||||
|
bool isSingleStringRef() const {
|
||||||
|
if (getRHSKind() != EmptyKind) return false;
|
||||||
|
|
||||||
|
switch (getLHSKind()) {
|
||||||
|
case EmptyKind:
|
||||||
|
case CStringKind:
|
||||||
|
case StdStringKind:
|
||||||
|
case StringRefKind:
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// @}
|
/// @}
|
||||||
/// @name String Operations
|
/// @name String Operations
|
||||||
@ -347,6 +363,20 @@ namespace llvm {
|
|||||||
/// SmallVector.
|
/// SmallVector.
|
||||||
void toVector(SmallVectorImpl<char> &Out) const;
|
void toVector(SmallVectorImpl<char> &Out) const;
|
||||||
|
|
||||||
|
/// getSingleStringRef - This returns the twine as a single StringRef. This
|
||||||
|
/// method is only valid if isSingleStringRef() is true.
|
||||||
|
StringRef getSingleStringRef() const {
|
||||||
|
assert(isSingleStringRef() &&"This cannot be had as a single stringref!");
|
||||||
|
switch (getLHSKind()) {
|
||||||
|
default: assert(0 && "Out of sync with isSingleStringRef");
|
||||||
|
case EmptyKind: return StringRef();
|
||||||
|
case CStringKind: return StringRef((const char*)LHS);
|
||||||
|
case StdStringKind: return StringRef(*(const std::string*)LHS);
|
||||||
|
case StringRefKind: return *(const StringRef*)LHS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// print - Write the concatenated string represented by this twine to the
|
/// print - Write the concatenated string represented by this twine to the
|
||||||
/// stream \arg OS.
|
/// stream \arg OS.
|
||||||
void print(raw_ostream &OS) const;
|
void print(raw_ostream &OS) const;
|
||||||
|
@ -188,8 +188,13 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix,
|
|||||||
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName,
|
||||||
const Twine &GVName, ManglerPrefixTy PrefixTy) {
|
const Twine &GVName, ManglerPrefixTy PrefixTy) {
|
||||||
SmallString<256> TmpData;
|
SmallString<256> TmpData;
|
||||||
GVName.toVector(TmpData);
|
StringRef Name;
|
||||||
StringRef Name = TmpData.str();
|
if (GVName.isSingleStringRef())
|
||||||
|
Name = GVName.getSingleStringRef();
|
||||||
|
else {
|
||||||
|
GVName.toVector(TmpData);
|
||||||
|
Name = TmpData.str();
|
||||||
|
}
|
||||||
assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
|
assert(!Name.empty() && "getNameWithPrefix requires non-empty name");
|
||||||
|
|
||||||
// If the global name is not led with \1, add the appropriate prefixes.
|
// If the global name is not led with \1, add the appropriate prefixes.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user