diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2010-01-13 12:45:23 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2010-01-13 12:45:23 +0000 |
commit | b357e06f672996400343d38b08014a5b6a7d5b2d (patch) | |
tree | 22907ea5714f0dd34cac34ec6ae92dcd6642c5f2 /lib/VMCore | |
parent | 81d22d87de93f501f90f55b6bbc63f5dd286797a (diff) |
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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@93317 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/VMCore')
-rw-r--r-- | lib/VMCore/Mangler.cpp | 11 | ||||
-rw-r--r-- | lib/VMCore/Metadata.cpp | 6 | ||||
-rw-r--r-- | lib/VMCore/Value.cpp | 15 |
3 files changed, 9 insertions, 23 deletions
diff --git a/lib/VMCore/Mangler.cpp b/lib/VMCore/Mangler.cpp index 69a24a0bc2..7d9f330f4c 100644 --- a/lib/VMCore/Mangler.cpp +++ b/lib/VMCore/Mangler.cpp @@ -41,8 +41,7 @@ void Mangler::makeNameProper(SmallVectorImpl<char> &OutName, const Twine &TheName, ManglerPrefixTy PrefixTy) { SmallString<256> TmpData; - TheName.toVector(TmpData); - StringRef X = TmpData.str(); + StringRef X = TheName.toStringRef(TmpData); assert(!X.empty() && "Cannot mangle empty strings"); if (!UseQuotes) { @@ -188,13 +187,7 @@ std::string Mangler::getMangledName(const GlobalValue *GV, const char *Suffix, void Mangler::getNameWithPrefix(SmallVectorImpl<char> &OutName, const Twine &GVName, ManglerPrefixTy PrefixTy) { SmallString<256> TmpData; - StringRef Name; - if (GVName.isSingleStringRef()) - Name = GVName.getSingleStringRef(); - else { - GVName.toVector(TmpData); - Name = TmpData.str(); - } + StringRef Name = GVName.toStringRef(TmpData); assert(!Name.empty() && "getNameWithPrefix requires non-empty name"); // If the global name is not led with \1, add the appropriate prefixes. diff --git a/lib/VMCore/Metadata.cpp b/lib/VMCore/Metadata.cpp index e6a962bbca..bac89bfd7b 100644 --- a/lib/VMCore/Metadata.cpp +++ b/lib/VMCore/Metadata.cpp @@ -327,12 +327,8 @@ void NamedMDNode::setName(const Twine &NewName) { assert (!NewName.isTriviallyEmpty() && "Invalid named metadata name!"); SmallString<256> NameData; - NewName.toVector(NameData); + StringRef NameRef = NewName.toStringRef(NameData); - const char *NameStr = NameData.data(); - unsigned NameLen = NameData.size(); - - StringRef NameRef = StringRef(NameStr, NameLen); // Name isn't changing? if (getName() == NameRef) return; diff --git a/lib/VMCore/Value.cpp b/lib/VMCore/Value.cpp index ecf2d4b774..40679bfc29 100644 --- a/lib/VMCore/Value.cpp +++ b/lib/VMCore/Value.cpp @@ -170,13 +170,10 @@ void Value::setName(const Twine &NewName) { 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 @@ void Value::setName(const Twine &NewName) { 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 @@ void Value::setName(const Twine &NewName) { // 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 @@ void Value::setName(const Twine &NewName) { 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); } |