From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id 430CB3857831; Wed, 4 May 2022 20:02:05 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 430CB3857831 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jason Merrill To: gcc-cvs@gcc.gnu.org Subject: [gcc r13-120] c++: optimize reshape_init X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: c2e846b539bb932d7f68f7e6b3e401c361cc3bf3 X-Git-Newrev: c8df7208864d863f58da55d42ff82663059930b1 Message-Id: <20220504200205.430CB3857831@sourceware.org> Date: Wed, 4 May 2022 20:02:05 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 May 2022 20:02:05 -0000 https://gcc.gnu.org/g:c8df7208864d863f58da55d42ff82663059930b1 commit r13-120-gc8df7208864d863f58da55d42ff82663059930b1 Author: Jason Merrill 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))