[PATCH] D119951: [demangler] Fix build breakage
Nathan Sidwell via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 16 08:13:47 PST 2022
urnathan updated this revision to Diff 409277.
urnathan edited the summary of this revision.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119951/new/
https://reviews.llvm.org/D119951
Files:
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h
Index: llvm/include/llvm/Demangle/Utility.h
===================================================================
--- llvm/include/llvm/Demangle/Utility.h
+++ llvm/include/llvm/Demangle/Utility.h
@@ -37,10 +37,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<char *>(std::realloc(Buffer, BufferCapacity));
if (Buffer == nullptr)
std::terminate();
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 <algorithm>
#include <array>
#include <cstdint>
#include <cstdlib>
@@ -38,10 +37,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<char *>(std::realloc(Buffer, BufferCapacity));
if (Buffer == nullptr)
std::terminate();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119951.409277.patch
Type: text/x-patch
Size: 2105 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220216/19d23fde/attachment.bin>
More information about the llvm-commits
mailing list