[demangler] Fix buffer growth
authorNathan Sidwell <nathan@acm.org>
Mon, 7 Feb 2022 19:33:08 +0000 (11:33 -0800)
committerNathan Sidwell <nathan@acm.org>
Mon, 14 Feb 2022 11:59:31 +0000 (03:59 -0800)
commit995c4f306890ad379de19106f053238ce89f1483
tree95fc23f27a9292f037feaa3c71544ae122b48b4d
parent5a43a278f7f6a9bba0a630634534a37e060f24d0
[demangler] Fix buffer growth

The output buffer growth algorithm had a few issues:

a) An off-by-one error in the initial size check, which uses
'>='. This error was safe, but could cause us to reallocate when there
was no need.

b) An inconsistency between the initial size check (>=) and the
post-doubling check (>).  The latter was somewhat obscured by the
swapped operands.

c) There would be many reallocs with an initially-small buffer.  Add a
little initialization hysteresis.

Reviewed By: ChuanqiXu

Differential Revision: https://reviews.llvm.org/D119177
libcxxabi/src/demangle/Utility.h
llvm/include/llvm/Demangle/Utility.h