public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-7655] gccrs: libproc_macro: Fix capacity update in tokenstream
@ 2024-01-16 17:51 Arthur Cohen
0 siblings, 0 replies; only message in thread
From: Arthur Cohen @ 2024-01-16 17:51 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:22ba7ea9eecbd1a19757d694b84e5a80b811b003
commit r14-7655-g22ba7ea9eecbd1a19757d694b84e5a80b811b003
Author: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Date: Thu May 18 16:18:58 2023 +0200
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>
Diff:
---
libgrust/libproc_macro/tokenstream.cc | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/libgrust/libproc_macro/tokenstream.cc b/libgrust/libproc_macro/tokenstream.cc
index 12d45431601..25e42dc3dc9 100644
--- a/libgrust/libproc_macro/tokenstream.cc
+++ b/libgrust/libproc_macro/tokenstream.cc
@@ -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++;
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2024-01-16 17:51 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-16 17:51 [gcc r14-7655] gccrs: libproc_macro: Fix capacity update in tokenstream Arthur Cohen
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).