]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++: speed up looking up the current class
authorJason Merrill <jason@redhat.com>
Wed, 9 Jun 2021 21:48:14 +0000 (17:48 -0400)
committerJason Merrill <jason@redhat.com>
Sat, 12 Jun 2021 04:58:11 +0000 (00:58 -0400)
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.

gcc/cp/pt.c

index 141388ad2e5a1c82210d5f3f187818e6a3a5c9c7..d4bb5cc5eafc47038ccd89509020de51154c0457 100644 (file)
@@ -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.  */