From: Yaron Keren Date: Tue, 17 Mar 2015 09:51:17 +0000 (+0000) Subject: Teach Twine to support SmallString. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8931755e80cd6624aebc0fa59ea78d609827d6ff;p=clang Teach Twine to support SmallString. Enable removing .str() member calls for these frequent cases. http://reviews.llvm.org/D6372 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@232465 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Sema/CodeCompleteConsumer.h b/include/clang/Sema/CodeCompleteConsumer.h index 647eb8b380..d24a925dd8 100644 --- a/include/clang/Sema/CodeCompleteConsumer.h +++ b/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/lib/Sema/CodeCompleteConsumer.cpp b/lib/Sema/CodeCompleteConsumer.cpp index 92d2aeb918..69ae4f01dc 100644 --- a/lib/Sema/CodeCompleteConsumer.cpp +++ b/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) {