summaryrefslogtreecommitdiffstats
path: root/llvm/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
commit2e06b93f43f79f018d10b982980199ca526d2739 (patch)
treee2c9170da1938986cd2dbc5ee25ca23122cf7552 /llvm/lib/Support/Twine.cpp
parent6a61b5203dc68982f547cff3d6cd068066417703 (diff)
downloadbcm5719-llvm-2e06b93f43f79f018d10b982980199ca526d2739.tar.gz
bcm5719-llvm-2e06b93f43f79f018d10b982980199ca526d2739.zip
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
Diffstat (limited to 'llvm/lib/Support/Twine.cpp')
-rw-r--r--llvm/lib/Support/Twine.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/llvm/lib/Support/Twine.cpp b/llvm/lib/Support/Twine.cpp
index 94464ffe4f0..21504e964ea 100644
--- a/llvm/lib/Support/Twine.cpp
+++ b/llvm/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) {
OpenPOWER on IntegriCloud