Author: Benjamin Kramer Date: 2020-05-02T17:12:44+02:00 New Revision: cc1c51655854627c126daf9ead4c701616564bde
URL: https://github.com/llvm/llvm-project/commit/cc1c51655854627c126daf9ead4c701616564bde DIFF: https://github.com/llvm/llvm-project/commit/cc1c51655854627c126daf9ead4c701616564bde.diff LOG: Use realloc for NestedNameSpecifierLocBuilder These allocations are so tiny that the buffer can be grown in-place most of the time. Added: Modified: clang/lib/AST/NestedNameSpecifier.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/NestedNameSpecifier.cpp b/clang/lib/AST/NestedNameSpecifier.cpp index e28463516a9f..87bf4e122ec8 100644 --- a/clang/lib/AST/NestedNameSpecifier.cpp +++ b/clang/lib/AST/NestedNameSpecifier.cpp @@ -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"); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits