Index: libcxxabi/src/demangle/Utility.h =================================================================== --- libcxxabi/src/demangle/Utility.h +++ libcxxabi/src/demangle/Utility.h @@ -38,10 +38,13 @@ void grow(size_t N) { size_t Need = N + CurrentPosition; if (Need > BufferCapacity) { - // Avoid many reallocations during startup, with a bit of hysteresis. - constexpr size_t MinInitAlloc = 1024; - Need = std::max(Need, MinInitAlloc); - BufferCapacity = std::max(Need, BufferCapacity * 2); + // Reduce the number of reallocations, with a bit of hysteresis. The + // number here is chosen so the first allocation will more-than-likely not + // allocate more than 1K. + Need += 1024 - 32; + BufferCapacity *= 2; + if (BufferCapacity < Need) + BufferCapacity = Need; Buffer = static_cast(std::realloc(Buffer, BufferCapacity)); if (Buffer == nullptr) std::terminate(); Index: llvm/include/llvm/Demangle/Utility.h =================================================================== --- llvm/include/llvm/Demangle/Utility.h +++ llvm/include/llvm/Demangle/Utility.h @@ -17,6 +17,7 @@ #define DEMANGLE_UTILITY_H #include "StringView.h" +#include #include #include #include @@ -37,10 +38,13 @@ void grow(size_t N) { size_t Need = N + CurrentPosition; if (Need > BufferCapacity) { - // Avoid many reallocations during startup, with a bit of hysteresis. - constexpr size_t MinInitAlloc = 1024; - Need = std::max(Need, MinInitAlloc); - BufferCapacity = std::max(Need, BufferCapacity * 2); + // Reduce the number of reallocations, with a bit of hysteresis. The + // number here is chosen so the first allocation will more-than-likely not + // allocate more than 1K. + Need += 1024 - 32; + BufferCapacity *= 2; + if (BufferCapacity < Need) + BufferCapacity = Need; Buffer = static_cast(std::realloc(Buffer, BufferCapacity)); if (Buffer == nullptr) std::terminate();