]> granicus.if.org Git - clang/commitdiff
Teach Twine to support SmallString.
authorYaron Keren <yaron.keren@gmail.com>
Tue, 17 Mar 2015 09:51:17 +0000 (09:51 +0000)
committerYaron Keren <yaron.keren@gmail.com>
Tue, 17 Mar 2015 09:51:17 +0000 (09:51 +0000)
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

include/clang/Sema/CodeCompleteConsumer.h
lib/Sema/CodeCompleteConsumer.cpp

index 647eb8b380830af4c72df5dbf6be6722e93b3638..d24a925dd889642c74875ce863882fa38d9f7199 100644 (file)
@@ -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.
index 92d2aeb91897fb2918cf0014b4faddc0477d4b10..69ae4f01dc7b5d0b6635a879f43eafe603c77c13 100644 (file)
@@ -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) {