]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: vec_safe_reserve usage tweaks
authorJason Merrill <jason@redhat.com>
Sun, 19 Jan 2025 10:15:01 +0000 (05:15 -0500)
committerJason Merrill <jason@redhat.com>
Thu, 17 Apr 2025 17:20:39 +0000 (13:20 -0400)
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
gcc/cp/rtti.cc

index 1cd982e12d49e00a75e6544774bceaedec5881a3..498126a191abcb14398aa40487a93a016aaff32a 100644 (file)
@@ -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];
index 353996206f5c5fd80c5b34a725a617228596108e..18bc479dc50b035d04418dd3c13aed1b469c1d0d 100644 (file)
@@ -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];