mirror of
https://gcc.gnu.org/git/gcc.git
synced 2024-11-26 21:33:59 +08:00
gccrs: libproc_macro: Fix capacity update in tokenstream
The capacity was not updated on tokenstream grow. This commit also add a new mechanism to prevent a tokenstream to grow with a zero delta capacity. libgrust/ChangeLog: * libproc_macro/tokenstream.cc (TokenStream::grow): Add minimum growing capacity. (TokenStream::push): Change condition. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
This commit is contained in:
parent
5c20c980f7
commit
22ba7ea9ee
@ -48,8 +48,9 @@ TokenStream::make_tokenstream (std::uint64_t capacity)
|
||||
void
|
||||
TokenStream::grow (std::uint64_t delta)
|
||||
{
|
||||
auto new_capacity = capacity + delta;
|
||||
auto new_capacity = capacity + (delta != 0 ? delta : 1);
|
||||
auto *new_data = new TokenTree[new_capacity];
|
||||
capacity = new_capacity;
|
||||
std::memcpy (new_data, data, size);
|
||||
delete[] data;
|
||||
data = new_data;
|
||||
@ -58,7 +59,7 @@ TokenStream::grow (std::uint64_t delta)
|
||||
void
|
||||
TokenStream::push (TokenTree tree)
|
||||
{
|
||||
if (size == capacity)
|
||||
if (size >= capacity)
|
||||
grow (capacity);
|
||||
data[size] = tree;
|
||||
size++;
|
||||
|
Loading…
Reference in New Issue
Block a user