https://gcc.gnu.org/g:53d4e355db18fec21515d055924df8290ef5ce14

commit r16-7-g53d4e355db18fec21515d055924df8290ef5ce14
Author: Jason Merrill <ja...@redhat.com>
Date:   Sun Jan 19 05:15:01 2025 -0500

    c++: vec_safe_reserve usage tweaks
    
    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.

Diff:
---
 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 1cd982e12d49..498126a191ab 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 353996206f5c..18bc479dc50b 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];

Reply via email to