[Basic] Move copyCString to Basic/StringExtras.

Also, use StringRef.copy() instead of copyString().
This commit is contained in:
Rintaro Ishizaki
2022-02-16 12:32:58 -08:00
parent 5ab84ae242
commit 7ef93b2a67
8 changed files with 41 additions and 50 deletions

View File

@@ -457,10 +457,14 @@ StringRef swift::matchLeadingTypeName(StringRef name,
return nameMismatch.getRestOfStr();
}
StringRef StringScratchSpace::copyString(StringRef string) {
void *memory = Allocator.Allocate(string.size(), alignof(char));
const char *swift::copyCString(StringRef string,
llvm::BumpPtrAllocator &Allocator) {
if (string.empty())
return "";
char *memory = Allocator.Allocate<char>(string.size() + 1);
memcpy(memory, string.data(), string.size());
return StringRef(static_cast<char *>(memory), string.size());
memory[string.size()] = '\0';
return memory;
}
void InheritedNameSet::add(StringRef name) {