]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++: record template specialization hash
authorJason Merrill <jason@redhat.com>
Thu, 3 Oct 2024 20:29:20 +0000 (16:29 -0400)
committerJason Merrill <jason@redhat.com>
Fri, 4 Oct 2024 01:43:21 +0000 (21:43 -0400)
commit5dad738c1dd1649a85d04a56f93d0ea229c9590f
treefe7e97a17f805f6353093069b375451c4a56010a
parente175fb380a33537b3ea7056fead1e6ed25309dc1
c++: record template specialization hash

A lot of compile time of template-heavy code is spent in re-hashing
hashtable elements upon expansion.  The following records the hash in the
hash element.  This speeds up C++20 compilation of stdc++.h by about 25% for
about a 0.1% increase in memory usage.

With the hash value in the entry, we don't need to pass it separately to the
find functions.

Adding default arguments to the spec and hash fields simplifies spec_entry
initialization and avoids problems from hash starting with an indeterminate
value.

gcc/cp/ChangeLog:

* cp-tree.h (spec_entry::hash): New member.
* pt.cc (spec_hasher::hash): Set it and return it.
(maybe_process_partial_specialization): Clear it when
changing tmpl/args.
(lookup_template_class): Likewise, don't pass hash to find.
(retrieve_specialization): Set it, don't pass hash to find.
(register_specialization): Don't pass hash to find.
(reregister_specialization): Likewise.
(match_mergeable_specialization): Likewise.
(add_mergeable_specialization): Likewise.

Co-authored-by: Richard Biener <rguenther@suse.de>
gcc/cp/cp-tree.h
gcc/cp/pt.cc