public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jason Merrill <jason@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r13-120] c++: optimize reshape_init
Date: Wed,  4 May 2022 20:02:05 +0000 (GMT)	[thread overview]
Message-ID: <20220504200205.430CB3857831@sourceware.org> (raw)

https://gcc.gnu.org/g:c8df7208864d863f58da55d42ff82663059930b1

commit r13-120-gc8df7208864d863f58da55d42ff82663059930b1
Author: Jason Merrill <jason@redhat.com>
Date:   Mon Mar 21 09:58:28 2022 -0400

    c++: optimize reshape_init
    
    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.

Diff:
---
 gcc/cp/decl.cc | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
index c9110db796a..0fa758ff214 100644
--- a/gcc/cp/decl.cc
+++ b/gcc/cp/decl.cc
@@ -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))


                 reply	other threads:[~2022-05-04 20:02 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220504200205.430CB3857831@sourceware.org \
    --to=jason@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).