]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: optimize reshape_init
authorJason Merrill <jason@redhat.com>
Mon, 21 Mar 2022 13:58:28 +0000 (09:58 -0400)
committerJason Merrill <jason@redhat.com>
Wed, 4 May 2022 20:01:35 +0000 (16:01 -0400)
If the index of a constructor_elt is a FIELD_DECL, the CONSTRUCTOR is
already reshaped, so we can save time and memory by returning immediately.

gcc/cp/ChangeLog:

* decl.cc (reshape_init): Shortcut already-reshaped init.
 (reshape_init_class): Assert not getting one here.

gcc/cp/decl.cc

index c9110db796adb2c9e0d775b0065580236e077619..0fa758ff214ee5d951044f09d6d11de0be6a3dab 100644 (file)
@@ -6631,7 +6631,9 @@ reshape_init_class (tree type, reshape_iter *d, bool first_initializer_p,
 
          if (TREE_CODE (d->cur->index) == FIELD_DECL)
            {
-             /* We already reshaped this.  */
+             /* We already reshaped this; we should have returned early from
+                reshape_init.  */
+             gcc_checking_assert (false);
              if (field != d->cur->index)
                {
                  if (tree id = DECL_NAME (d->cur->index))
@@ -7068,6 +7070,10 @@ reshape_init (tree type, tree init, tsubst_flags_t complain)
   if (vec_safe_is_empty (v))
     return init;
 
+  if ((*v)[0].index && TREE_CODE ((*v)[0].index) == FIELD_DECL)
+    /* Already reshaped.  */
+    return init;
+
   /* Brace elision is not performed for a CONSTRUCTOR representing
      parenthesized aggregate initialization.  */
   if (CONSTRUCTOR_IS_PAREN_INIT (init))