Index: libcxxabi/src/demangle/Utility.h =================================================================== --- libcxxabi/src/demangle/Utility.h +++ libcxxabi/src/demangle/Utility.h @@ -17,7 +17,6 @@ #define DEMANGLE_UTILITY_H #include "StringView.h" -#include #include #include #include @@ -40,8 +39,11 @@ 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); + if (Need < MinInitAlloc) + Need = MinInitAlloc; + 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 @@ -39,8 +39,11 @@ 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); + if (Need < MinInitAlloc) + Need = MinInitAlloc; + BufferCapacity *= 2; + if (BufferCapacity < Need) + BufferCapacity = Need; Buffer = static_cast(std::realloc(Buffer, BufferCapacity)); if (Buffer == nullptr) std::terminate();