Use realloc for NestedNameSpecifierLocBuilder

These allocations are so tiny that the buffer can be grown in-place most
of the time.
This commit is contained in:
Benjamin Kramer 2020-05-02 17:04:52 +02:00
parent ece7e95f02
commit cc1c516558
1 changed files with 7 additions and 6 deletions

View File

@ -464,13 +464,14 @@ static void Append(char *Start, char *End, char *&Buffer, unsigned &BufferSize,
unsigned NewCapacity = std::max(
(unsigned)(BufferCapacity ? BufferCapacity * 2 : sizeof(void *) * 2),
(unsigned)(BufferSize + (End - Start)));
char *NewBuffer = static_cast<char *>(llvm::safe_malloc(NewCapacity));
if (Buffer) {
memcpy(NewBuffer, Buffer, BufferSize);
if (BufferCapacity)
free(Buffer);
if (!BufferCapacity) {
char *NewBuffer = static_cast<char *>(llvm::safe_malloc(NewCapacity));
if (Buffer)
memcpy(NewBuffer, Buffer, BufferSize);
Buffer = NewBuffer;
} else {
Buffer = static_cast<char *>(llvm::safe_realloc(Buffer, NewCapacity));
}
Buffer = NewBuffer;
BufferCapacity = NewCapacity;
}
assert(Buffer && Start && End && End > Start && "Illegal memory buffer copy");