summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorYaron Keren <yaron.keren@gmail.com>2015-03-17 09:51:17 +0000
committerYaron Keren <yaron.keren@gmail.com>2015-03-17 09:51:17 +0000
commit1ee89fc432ded040593e59844efa621b4189a7c3 (patch)
tree14eac32a31a8d2e7c2180ff3ecaa3830aeb93c5d /clang
parente458ab45774966c263817fdd63613faf28cf843c (diff)
downloadbcm5719-llvm-1ee89fc432ded040593e59844efa621b4189a7c3.tar.gz
bcm5719-llvm-1ee89fc432ded040593e59844efa621b4189a7c3.zip
Teach Twine to support SmallString.
Enable removing .str() member calls for these frequent cases. http://reviews.llvm.org/D6372 llvm-svn: 232465
Diffstat (limited to 'clang')
-rw-r--r--clang/include/clang/Sema/CodeCompleteConsumer.h15
-rw-r--r--clang/lib/Sema/CodeCompleteConsumer.cpp17
2 files changed, 8 insertions, 24 deletions
diff --git a/clang/include/clang/Sema/CodeCompleteConsumer.h b/clang/include/clang/Sema/CodeCompleteConsumer.h
index 647eb8b3808..d24a925dd88 100644
--- a/clang/include/clang/Sema/CodeCompleteConsumer.h
+++ b/clang/include/clang/Sema/CodeCompleteConsumer.h
@@ -499,20 +499,7 @@ public:
class CodeCompletionAllocator : public llvm::BumpPtrAllocator {
public:
/// \brief Copy the given string into this allocator.
- const char *CopyString(StringRef String);
-
- /// \brief Copy the given string into this allocator.
- const char *CopyString(Twine String);
-
- // \brief Copy the given string into this allocator.
- const char *CopyString(const char *String) {
- return CopyString(StringRef(String));
- }
-
- /// \brief Copy the given string into this allocator.
- const char *CopyString(const std::string &String) {
- return CopyString(StringRef(String));
- }
+ const char *CopyString(const Twine &String);
};
/// \brief Allocator for a cached set of global code completions.
diff --git a/clang/lib/Sema/CodeCompleteConsumer.cpp b/clang/lib/Sema/CodeCompleteConsumer.cpp
index 92d2aeb9189..69ae4f01dc7 100644
--- a/clang/lib/Sema/CodeCompleteConsumer.cpp
+++ b/clang/lib/Sema/CodeCompleteConsumer.cpp
@@ -251,19 +251,16 @@ const char *CodeCompletionString::getTypedText() const {
return nullptr;
}
-const char *CodeCompletionAllocator::CopyString(StringRef String) {
- char *Mem = (char *)Allocate(String.size() + 1, 1);
- std::copy(String.begin(), String.end(), Mem);
- Mem[String.size()] = 0;
- return Mem;
-}
-
-const char *CodeCompletionAllocator::CopyString(Twine String) {
+const char *CodeCompletionAllocator::CopyString(const Twine &String) {
+ SmallString<128> Data;
+ StringRef Ref = String.toStringRef(Data);
// FIXME: It would be more efficient to teach Twine to tell us its size and
// then add a routine there to fill in an allocated char* with the contents
// of the string.
- SmallString<128> Data;
- return CopyString(String.toStringRef(Data));
+ char *Mem = (char *)Allocate(Ref.size() + 1, 1);
+ std::copy(Ref.begin(), Ref.end(), Mem);
+ Mem[Ref.size()] = 0;
+ return Mem;
}
StringRef CodeCompletionTUInfo::getParentName(const DeclContext *DC) {
OpenPOWER on IntegriCloud