summaryrefslogtreecommitdiffstats
path: root/gcc/c-decl.c
diff options
context:
space:
mode:
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-16 18:45:56 +0000
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>2003-07-16 18:45:56 +0000
commit860251bec40a1182f2cec4c8039a6120c165271f (patch)
tree39a0963ec716fc0d03212b9d1c71114101da5421 /gcc/c-decl.c
parent1b5e83e3125575a01fe598726438f4861f2ba7d4 (diff)
downloadppe42-gcc-860251bec40a1182f2cec4c8039a6120c165271f.tar.gz
ppe42-gcc-860251bec40a1182f2cec4c8039a6120c165271f.zip
2003-07-16 Andrew Pinski <pinskia@physics.uc.edu>
ChangeLog: PR c/10962 * ggc.h: Add header guards. * c-decl.c (finish_struct): Sort fields if number greater than 15 and there are no anonymous structs/unions. * c-common.h: Include ggc.h. (sorted_fields_type): New struct. (field_decl_cmp): New prototype. (resort_sorted_fields): New prototype. (DECL_DECLARES_TYPE_NON_TEMPLATE_P): New macro. * c-tree.h: (lang_type): Use pointer to sorted_fields_type as s, removing other fields. * c-typeck.c (lookup_field): Use s in lang_type. These were mostly moved from cp/class.c: * c-common.c (field_decl_cmp): New static function. (field_decl_cmp): New function. (resort_sorted_fields): New function. cp/ChangeLog: * class.c (field_decl_cmp): Remove. (resort_field_decl_cmp): Remove. (resort_sorted_fields): Remove. (add_fields_to_vec): Rename to ... (add_fields_to_record_type): this. (finish_struct_1): Change to be using sorted_fields_type's fields. * cp-tree.h (lang_decl): In lang_decl_u3 change sorted_fields to be a pointer to sorted_fields_type. (resort_sorted_fields): Remove prototype. * search.c (lookup_field_1): Change to be using sorted_fields_type's fields. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@69470 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/c-decl.c')
-rw-r--r--gcc/c-decl.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 80e6b68fa2e..c643d97193d 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -5155,6 +5155,56 @@ finish_struct (tree t, tree fieldlist, tree attributes)
TYPE_FIELDS (t) = fieldlist;
+ /* If there are lots of fields, sort so we can look through them fast.
+ We arbitrarily consider 16 or more elts to be "a lot". */
+
+ {
+ int len = 0;
+
+ for (x = fieldlist; x; x = TREE_CHAIN (x))
+ {
+ if (len > 15 || DECL_NAME (x) == NULL)
+ break;
+ len += 1;
+ }
+
+ if (len > 15)
+ {
+ tree *field_array;
+ struct lang_type *space;
+ struct sorted_fields_type *space2;
+
+ len += list_length (x);
+
+ /* Use the same allocation policy here that make_node uses, to
+ ensure that this lives as long as the rest of the struct decl.
+ All decls in an inline function need to be saved. */
+
+ space = ggc_alloc (sizeof (struct lang_type));
+ space2 = ggc_alloc (sizeof (struct sorted_fields_type) + len * sizeof (tree));
+
+ len = 0;
+ space->s = space2;
+ field_array = &space2->elts[0];
+ for (x = fieldlist; x; x = TREE_CHAIN (x))
+ {
+ field_array[len++] = x;
+
+ /* if there is anonymous struct or union break out of the loop */
+ if (DECL_NAME (x) == NULL)
+ break;
+ }
+ /* found no anonymous struct/union add the TYPE_LANG_SPECIFIC. */
+ if (x == NULL)
+ {
+ TYPE_LANG_SPECIFIC (t) = space;
+ TYPE_LANG_SPECIFIC (t)->s->len = len;
+ field_array = TYPE_LANG_SPECIFIC (t)->s->elts;
+ qsort (field_array, len, sizeof (tree), field_decl_cmp);
+ }
+ }
+ }
+
for (x = TYPE_MAIN_VARIANT (t); x; x = TYPE_NEXT_VARIANT (x))
{
TYPE_FIELDS (x) = TYPE_FIELDS (t);
OpenPOWER on IntegriCloud