[PATCH] D119177: [demangler] Fix buffer growth
Nathan Sidwell via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 03:59:23 PST 2022
urnathan marked an inline comment as done.
urnathan added inline comments.
================
Comment at: libcxxabi/src/demangle/Utility.h:43-45
+ constexpr size_t MinAlloc = 1024;
+ if (!BufferCapacity && Need < MinAlloc)
+ Need = MinAlloc;
----------------
ChuanqiXu wrote:
> urnathan wrote:
> > ChuanqiXu wrote:
> > > It looks like that `MinInitAlloc` is a better name. I would like to move line 43~45 after line 38. Then we could simplify the code to:
> > > ```
> > > size_t Need = N + CurrentPosition;
> > > /// A comment here
> > > constexpr size_t MinInitAlloc = 1024;
> > > if (!BufferCapacity)
> > > Need = max(Need, MinInitAlloc);
> > > if (Need > BufferCapacity)
> > > BufferCapacity = max(Need, BufferCapacity * 2);
> > > ```
> > I put the MinInitAlloc checking inside the outer if, to avoid making the non-allocating path more complex. We only need to check the minium when we know we're going to allocate
> Now it lost the check: `if (!BufferCapacity)`. Is it intentional? Now it wouldn't allocate at the initialization only. So the name may be not appropriate.
that check is unnecessary, we'll only pick MinInitAlloc on the first allocation -- because later allocations will be for a greater amount.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119177/new/
https://reviews.llvm.org/D119177
More information about the llvm-commits
mailing list