aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2020-05-13 13:11:36 -0700
committerGiuliano Belinassi <giuliano.belinassi@usp.br>2020-08-17 13:03:16 -0300
commit52de2499edbbeda89e5f4c05c9ae84525dd00a56 (patch)
treef9b75f3312d57f002d1024bbb7f0cd0f93651872 /gcc
parent8ec49600712251bfa31e2ce121ceb853ff9d03c2 (diff)
downloadgcc-52de2499edbbeda89e5f4c05c9ae84525dd00a56.zip
gcc-52de2499edbbeda89e5f4c05c9ae84525dd00a56.tar.gz
gcc-52de2499edbbeda89e5f4c05c9ae84525dd00a56.tar.bz2
c++: Simplify canonical_type_parameter
Use a single vec_safe_grow_cleared, rather than that or a vec_alloc. Use a for loop that returns early. * pt.c (canonical_type_parameter): Simplify.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog2
-rw-r--r--gcc/cp/pt.c24
2 files changed, 10 insertions, 16 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index b75025f..10f212f 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,5 +1,7 @@
2020-05-13 Nathan Sidwell <nathan@acm.org>
+ * pt.c (canonical_type_parameter): Simplify.
+
Formatting fixups & some simplifications.
* pt.c (spec_hash_table): New typedef.
(decl_specializations, type_specializations): Use it.
diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c
index a732ced..ec2ca3e 100644
--- a/gcc/cp/pt.c
+++ b/gcc/cp/pt.c
@@ -4417,29 +4417,21 @@ build_template_parm_index (int index,
static tree
canonical_type_parameter (tree type)
{
- tree list;
int idx = TEMPLATE_TYPE_IDX (type);
gcc_assert (TREE_CODE (type) != TEMPLATE_TEMPLATE_PARM);
- if (!canonical_template_parms)
- vec_alloc (canonical_template_parms, idx + 1);
-
- if (canonical_template_parms->length () <= (unsigned) idx)
+ if (vec_safe_length (canonical_template_parms) <= (unsigned) idx)
vec_safe_grow_cleared (canonical_template_parms, idx + 1);
- list = (*canonical_template_parms)[idx];
- while (list && !comptypes (type, TREE_VALUE (list), COMPARE_STRUCTURAL))
- list = TREE_CHAIN (list);
+ for (tree list = (*canonical_template_parms)[idx];
+ list; list = TREE_CHAIN (list))
+ if (comptypes (type, TREE_VALUE (list), COMPARE_STRUCTURAL))
+ return TREE_VALUE (list);
- if (list)
- return TREE_VALUE (list);
- else
- {
- (*canonical_template_parms)[idx]
- = tree_cons (NULL_TREE, type, (*canonical_template_parms)[idx]);
- return type;
- }
+ (*canonical_template_parms)[idx]
+ = tree_cons (NULL_TREE, type, (*canonical_template_parms)[idx]);
+ return type;
}
/* Return a TEMPLATE_PARM_INDEX, similar to INDEX, but whose