aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorJason Merrill <jason@redhat.com>2021-06-09 17:48:14 -0400
committerJason Merrill <jason@redhat.com>2021-06-12 00:58:11 -0400
commitc4e50e500da7692aad53a4488aff32e056149b3c (patch)
tree1893d70592702b1fa233133ec164bee1d8e1673d /gcc
parentf16f65f8364b5bf23c72a8fdbba4974ecadc5cb6 (diff)
downloadgcc-c4e50e500da7692aad53a4488aff32e056149b3c.zip
gcc-c4e50e500da7692aad53a4488aff32e056149b3c.tar.gz
gcc-c4e50e500da7692aad53a4488aff32e056149b3c.tar.bz2
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/pt.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index 141388a..d4bb5cc 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. */