This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH] Change local_specializations from htab_t to pointer map
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Jason Merrill <jason at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Mon, 5 Mar 2012 12:15:42 +0100
- Subject: [C++ PATCH] Change local_specializations from htab_t to pointer map
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
Hi!
This patch changes local_specializations into a pointer map.
Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
2012-03-05 Jakub Jelinek <jakub@redhat.com>
* pt.c (local_specializations): Change from htab_t into
struct pointer_map_t *.
(retrieve_local_specializations, register_local_specialization,
tsubst_pack_expansion, instantiate_decl): Adjust users.
(eq_local_specializations, hash_local_specialization): Remove.
--- gcc/cp/pt.c.jj 2012-02-15 07:35:05.013340385 +0100
+++ gcc/cp/pt.c 2012-03-05 08:20:55.422649037 +0100
@@ -79,7 +79,7 @@ static tree cur_stmt_expr;
/* A map from local variable declarations in the body of the template
presently being instantiated to the corresponding instantiated
local variables. */
-static htab_t local_specializations;
+static struct pointer_map_t *local_specializations;
typedef struct GTY(()) spec_entry
{
@@ -189,7 +189,6 @@ static tree for_each_template_parm_r (tr
static tree copy_default_args_to_explicit_spec_1 (tree, tree);
static void copy_default_args_to_explicit_spec (tree);
static int invalid_nontype_parm_type_p (tree, tsubst_flags_t);
-static int eq_local_specializations (const void *, const void *);
static bool dependent_template_arg_p (tree);
static bool any_template_arguments_need_structural_equality_p (tree);
static bool dependent_type_p_r (tree);
@@ -1078,14 +1077,13 @@ retrieve_specialization (tree tmpl, tree
static tree
retrieve_local_specialization (tree tmpl)
{
- tree spec;
+ void **slot;
if (local_specializations == NULL)
return NULL_TREE;
- spec = (tree) htab_find_with_hash (local_specializations, tmpl,
- htab_hash_pointer (tmpl));
- return spec ? TREE_PURPOSE (spec) : NULL_TREE;
+ slot = pointer_map_contains (local_specializations, tmpl);
+ return slot ? (tree) *slot : NULL_TREE;
}
/* Returns nonzero iff DECL is a specialization of TMPL. */
@@ -1677,24 +1675,6 @@ reregister_specialization (tree spec, tr
return 0;
}
-/* Compare an entry in the local specializations hash table P1 (which
- is really a pointer to a TREE_LIST) with P2 (which is really a
- DECL). */
-
-static int
-eq_local_specializations (const void *p1, const void *p2)
-{
- return TREE_VALUE ((const_tree) p1) == (const_tree) p2;
-}
-
-/* Hash P1, an entry in the local specializations table. */
-
-static hashval_t
-hash_local_specialization (const void* p1)
-{
- return htab_hash_pointer (TREE_VALUE ((const_tree) p1));
-}
-
/* Like register_specialization, but for local declarations. We are
registering SPEC, an instantiation of TMPL. */
@@ -1703,9 +1683,8 @@ register_local_specialization (tree spec
{
void **slot;
- slot = htab_find_slot_with_hash (local_specializations, tmpl,
- htab_hash_pointer (tmpl), INSERT);
- *slot = build_tree_list (spec, tmpl);
+ slot = pointer_map_insert (local_specializations, tmpl);
+ *slot = spec;
}
/* TYPE is a class type. Returns true if TYPE is an explicitly
@@ -9307,7 +9286,7 @@ tsubst_pack_expansion (tree t, tree args
int missing_level = 0;
int i, len = -1;
tree result;
- htab_t saved_local_specializations = NULL;
+ struct pointer_map_t *saved_local_specializations = NULL;
bool need_local_specializations = false;
int levels;
@@ -9492,14 +9471,11 @@ tsubst_pack_expansion (tree t, tree args
if (need_local_specializations)
{
/* We're in a late-specified return type, so create our own local
- specializations table; the current table is either NULL or (in the
+ specializations map; the current map is either NULL or (in the
case of recursive unification) might have bindings that we don't
want to use or alter. */
saved_local_specializations = local_specializations;
- local_specializations = htab_create (37,
- hash_local_specialization,
- eq_local_specializations,
- NULL);
+ local_specializations = pointer_map_create ();
}
/* For each argument in each argument pack, substitute into the
@@ -9586,7 +9562,7 @@ tsubst_pack_expansion (tree t, tree args
if (need_local_specializations)
{
- htab_delete (local_specializations);
+ pointer_map_destroy (local_specializations);
local_specializations = saved_local_specializations;
}
@@ -18704,7 +18680,7 @@ instantiate_decl (tree d, int defer_ok,
synthesize_method (d);
else if (TREE_CODE (d) == FUNCTION_DECL)
{
- htab_t saved_local_specializations;
+ struct pointer_map_t *saved_local_specializations;
tree subst_decl;
tree tmpl_parm;
tree spec_parm;
@@ -18714,10 +18690,7 @@ instantiate_decl (tree d, int defer_ok,
saved_local_specializations = local_specializations;
/* Set up the list of local specializations. */
- local_specializations = htab_create (37,
- hash_local_specialization,
- eq_local_specializations,
- NULL);
+ local_specializations = pointer_map_create ();
/* Set up context. */
start_preparsed_function (d, NULL_TREE, SF_PRE_PARSED);
@@ -18759,7 +18732,7 @@ instantiate_decl (tree d, int defer_ok,
input_location = DECL_STRUCT_FUNCTION (code_pattern)->function_end_locus;
/* We don't need the local specializations any more. */
- htab_delete (local_specializations);
+ pointer_map_destroy (local_specializations);
local_specializations = saved_local_specializations;
/* Finish the function. */
Jakub