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/Value.cpp | |
parent | 81d22d87de93f501f90f55b6bbc63f5dd286797a (diff) | |
download | llvm-b357e06f672996400343d38b08014a5b6a7d5b2d.tar.gz llvm-b357e06f672996400343d38b08014a5b6a7d5b2d.tar.bz2 llvm-b357e06f672996400343d38b08014a5b6a7d5b2d.tar.xz |
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/Value.cpp')
-rw-r--r-- | lib/VMCore/Value.cpp | 15 |
1 files changed, 6 insertions, 9 deletions
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); } |