public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1403] c++: speed up looking up the current class
@ 2021-06-12  4:59 Jason Merrill
  0 siblings, 0 replies; only message in thread
From: Jason Merrill @ 2021-06-12  4:59 UTC (permalink / raw)
  To: gcc-cvs

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

commit r12-1403-gc4e50e500da7692aad53a4488aff32e056149b3c
Author: Jason Merrill <jason@redhat.com>
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.  */


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-12  4:59 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-12  4:59 [gcc r12-1403] c++: speed up looking up the current class Jason Merrill

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).