Tested x86_64-pc-linux-gnu, applying to trunk.
-- 8< --
A couple of cleanups from noticing that the semantics of
std::vector<T>::reserve() (request the new minimum allocation) differ from
the GCC vec<...>::reserve() (request a minimum number of slots available).
In preserve_state, we were tripling the size of the vec when doubling it is
more than enough.
In get_tinfo_desc we were using vec_safe_reserve properly, but it's
simpler to use vec_safe_grow_cleared.
gcc/cp/ChangeLog:
* name-lookup.cc (name_lookup::preserve_state): Fix reserve call.
* rtti.cc (get_tinfo_desc): Use vec_safe_grow_cleared.
---
gcc/cp/name-lookup.cc | 2 +-
gcc/cp/rtti.cc | 15 +++------------
2 files changed, 4 insertions(+), 13 deletions(-)
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 1cd982e12d4..498126a191a 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -583,7 +583,7 @@ name_lookup::preserve_state ()
if (previous)
{
unsigned length = vec_safe_length (previous->scopes);
- vec_safe_reserve (previous->scopes, length * 2);
+ vec_safe_reserve (previous->scopes, length);
for (unsigned ix = length; ix--;)
{
tree decl = (*previous->scopes)[ix];
diff --git a/gcc/cp/rtti.cc b/gcc/cp/rtti.cc
index 353996206f5..18bc479dc50 100644
--- a/gcc/cp/rtti.cc
+++ b/gcc/cp/rtti.cc
@@ -1318,18 +1318,9 @@ get_pseudo_ti_index (tree type)
static tinfo_s *
get_tinfo_desc (unsigned ix)
{
- unsigned len = tinfo_descs->length ();
-
- if (len <= ix)
- {
- /* too short, extend. */
- len = ix + 1 - len;
- vec_safe_reserve (tinfo_descs, len);
- tinfo_s elt;
- elt.type = elt.vtable = elt.name = NULL_TREE;
- while (len--)
- tinfo_descs->quick_push (elt);
- }
+ if (tinfo_descs->length () <= ix)
+ /* too short, extend. */
+ vec_safe_grow_cleared (tinfo_descs, ix + 1);
tinfo_s *res = &(*tinfo_descs)[ix];
base-commit: 20e31f507a2dd6cbd40cc65a7c06d07bfaa2a5e1
--
2.49.0