This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Factor out allocation of sorted_fields (issue5253050)
- From: dnovillo at google dot com (Diego Novillo)
- To: reply at codereview dot appspotmail dot com, jason at redhat dot com, gcc-patches at gcc dot gnu dot org
- Date: Wed, 12 Oct 2011 15:13:12 -0400 (EDT)
- Subject: Factor out allocation of sorted_fields (issue5253050)
This moves the allocation of sorted_fields_type elements into a new
allocator function. It's not completely necessary in trunk, but in
the pph branch we need to allocate this type from pph images, so we
need to call it from outside of class.c
OK for trunk?
Tested on x86_64.
Diego.
* class.c (sorted_fields_type_new): Factor out of ...
(finish_struct_1): ... here.
diff --git a/gcc/cp/class.c b/gcc/cp/class.c
index 2df9177..6185054 100644
--- a/gcc/cp/class.c
+++ b/gcc/cp/class.c
@@ -5663,6 +5663,22 @@ determine_key_method (tree type)
return;
}
+
+/* Allocate and return an instance of struct sorted_fields_type with
+ N fields. */
+
+static struct sorted_fields_type *
+sorted_fields_type_new (int n)
+{
+ struct sorted_fields_type *sft;
+ sft = ggc_alloc_sorted_fields_type (sizeof (struct sorted_fields_type)
+ + n * sizeof (tree));
+ sft->len = n;
+
+ return sft;
+}
+
+
/* Perform processing required when the definition of T (a class type)
is complete. */
@@ -5792,9 +5808,7 @@ finish_struct_1 (tree t)
n_fields = count_fields (TYPE_FIELDS (t));
if (n_fields > 7)
{
- struct sorted_fields_type *field_vec = ggc_alloc_sorted_fields_type
- (sizeof (struct sorted_fields_type) + n_fields * sizeof (tree));
- field_vec->len = n_fields;
+ struct sorted_fields_type *field_vec = sorted_fields_type_new (n_fields);
add_fields_to_record_type (TYPE_FIELDS (t), field_vec, 0);
qsort (field_vec->elts, n_fields, sizeof (tree),
field_decl_cmp);
--
1.7.3.1
--
This patch is available for review at http://codereview.appspot.com/5253050