summaryrefslogtreecommitdiff
path: root/lib/Support/Twine.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-01-13 12:45:23 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-01-13 12:45:23 +0000
commitb357e06f672996400343d38b08014a5b6a7d5b2d (patch)
tree22907ea5714f0dd34cac34ec6ae92dcd6642c5f2 /lib/Support/Twine.cpp
parent81d22d87de93f501f90f55b6bbc63f5dd286797a (diff)
downloadllvm-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/Support/Twine.cpp')
-rw-r--r--lib/Support/Twine.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/Support/Twine.cpp b/lib/Support/Twine.cpp
index 94464ffe4f..21504e964e 100644
--- a/lib/Support/Twine.cpp
+++ b/lib/Support/Twine.cpp
@@ -15,8 +15,7 @@ using namespace llvm;
std::string Twine::str() const {
SmallString<256> Vec;
- toVector(Vec);
- return std::string(Vec.begin(), Vec.end());
+ return toStringRef(Vec).str();
}
void Twine::toVector(SmallVectorImpl<char> &Out) const {
@@ -24,6 +23,13 @@ void Twine::toVector(SmallVectorImpl<char> &Out) const {
print(OS);
}
+StringRef Twine::toStringRef(SmallVectorImpl<char> &Out) const {
+ if (isSingleStringRef())
+ return getSingleStringRef();
+ toVector(Out);
+ return StringRef(Out.data(), Out.size());
+}
+
void Twine::printOneChild(raw_ostream &OS, const void *Ptr,
NodeKind Kind) const {
switch (Kind) {