From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2122) id DAF9A3848004; Sat, 12 Jun 2021 04:59:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DAF9A3848004 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 r12-1403] c++: speed up looking up the current class X-Act-Checkin: gcc X-Git-Author: Jason Merrill X-Git-Refname: refs/heads/master X-Git-Oldrev: f16f65f8364b5bf23c72a8fdbba4974ecadc5cb6 X-Git-Newrev: c4e50e500da7692aad53a4488aff32e056149b3c Message-Id: <20210612045908.DAF9A3848004@sourceware.org> Date: Sat, 12 Jun 2021 04:59:08 +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: Sat, 12 Jun 2021 04:59:09 -0000 https://gcc.gnu.org/g:c4e50e500da7692aad53a4488aff32e056149b3c commit r12-1403-gc4e50e500da7692aad53a4488aff32e056149b3c Author: Jason Merrill Date: Wed Jun 9 17:48:14 2021 -0400 c++: speed up looking up the current class While looking at template instantiation tracing, I noticed that we were frequently looking up a particular class template instance while instantiating it. This patch shortcuts that lookup, and speeds up compiling stdc++.h with my (checking/unoptimized) compiler by about 3%. gcc/cp/ChangeLog: * pt.c (lookup_template_class_1): Shortcut current_class_type. Diff: --- gcc/cp/pt.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 141388ad2e5..d4bb5cc5eaf 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -9833,6 +9833,13 @@ lookup_template_class_1 (tree d1, tree arglist, tree in_decl, tree context, /* From here on, we're only interested in the most general template. */ + /* Shortcut looking up the current class scope again. */ + if (current_class_type) + if (tree ti = CLASSTYPE_TEMPLATE_INFO (current_class_type)) + if (gen_tmpl == most_general_template (TI_TEMPLATE (ti)) + && comp_template_args (arglist, TI_ARGS (ti))) + return current_class_type; + /* Calculate the BOUND_ARGS. These will be the args that are actually tsubst'd into the definition to create the instantiation. */