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:
Pierre-Emmanuel Patry 2023-05-18 16:18:58 +02:00 committed by Arthur Cohen
parent 5c20c980f7
commit 22ba7ea9ee

View File

@ -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++;