Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/llvm/llvm-project.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2022-02-16 19:03:24 +0300
committerNathan Sidwell <nathan@acm.org>2022-03-01 15:37:24 +0300
commit024495e62660a51edd060b57a95ca68d584d3b43 (patch)
tree1aa204fc7ba9816e01925adc770fbad79312f1f7 /libcxxabi/src/demangle
parente5c98e22fbbe3c3eb5f2c782d0789098afc81518 (diff)
[demangler] Improve buffer hysteresis
Improve demangler buffer hysteresis. If we needed more than double the buffer, the original code would allocate exactly the amount needed, and thus consequently the next request would also realloc. We're very unlikely to get into wanting more than double, after the first allocation, as it would require the user to have used an identifier larger than the hysteresis. With machine generated code that's possible, but unlikely. Reviewed By: ChuanqiXu Differential Revision: https://reviews.llvm.org/D119972
Diffstat (limited to 'libcxxabi/src/demangle')
-rw-r--r--libcxxabi/src/demangle/Utility.h8
1 files changed, 4 insertions, 4 deletions
diff --git a/libcxxabi/src/demangle/Utility.h b/libcxxabi/src/demangle/Utility.h
index f8190b81332a..0cf70bdde403 100644
--- a/libcxxabi/src/demangle/Utility.h
+++ b/libcxxabi/src/demangle/Utility.h
@@ -37,10 +37,10 @@ class OutputBuffer {
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;
- if (Need < MinInitAlloc)
- Need = MinInitAlloc;
+ // 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;