Introduce Twine::toStringRef, a variant of toVector which avoids the copy if the
twine can be represented as a single StringRef. Use the new methode to simplify
some twine users.
llvm-svn: 93317
diff --git a/llvm/lib/VMCore/Value.cpp b/llvm/lib/VMCore/Value.cpp
index ecf2d4b..40679bf 100644
--- a/llvm/lib/VMCore/Value.cpp
+++ b/llvm/lib/VMCore/Value.cpp
@@ -170,13 +170,10 @@
return;
SmallString<256> NameData;
- NewName.toVector(NameData);
-
- const char *NameStr = NameData.data();
- unsigned NameLen = NameData.size();
+ StringRef NameRef = NewName.toStringRef(NameData);
// Name isn't changing?
- if (getName() == StringRef(NameStr, NameLen))
+ if (getName() == NameRef)
return;
assert(!getType()->isVoidTy() && "Cannot assign a name to void values!");
@@ -187,7 +184,7 @@
return; // Cannot set a name on this value (e.g. constant).
if (!ST) { // No symbol table to update? Just do the change.
- if (NameLen == 0) {
+ if (NameRef.empty()) {
// Free the name for this value.
Name->Destroy();
Name = 0;
@@ -201,7 +198,7 @@
// then reallocated.
// Create the new name.
- Name = ValueName::Create(NameStr, NameStr+NameLen);
+ Name = ValueName::Create(NameRef.begin(), NameRef.end());
Name->setValue(this);
return;
}
@@ -214,12 +211,12 @@
Name->Destroy();
Name = 0;
- if (NameLen == 0)
+ if (NameRef.empty())
return;
}
// Name is changing to something new.
- Name = ST->createValueName(StringRef(NameStr, NameLen), this);
+ Name = ST->createValueName(NameRef, this);
}