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.
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) {