GCC Bugzilla – Attachment 4072 Details for
Bug 10962
[3.3 regression] lookup_field is a linear search on a linked list (can be slow if large struct)
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Patch for 3.3.
fixPR10962.txt (text/plain), 3.25 KB, created by
Andrew Pinski
on 2003-05-25 19:07:36 UTC
(
hide
)
Description:
Patch for 3.3.
Filename:
MIME Type:
Creator:
Andrew Pinski
Created:
2003-05-25 19:07:36 UTC
Size:
3.25 KB
patch
obsolete
>fixPR10962.diffxºömBIN`EIndex: c-decl.c >=================================================================== >RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v >retrieving revision 1.390 >diff -u -d -b -w -u -p -r1.390 c-decl.c >--- c-decl.c 22 May 2003 19:39:13 -0000 1.390 >+++ c-decl.c 25 May 2003 18:38:55 -0000 >@@ -280,8 +281,10 @@ static tree any_external_decl PARAMS (( > static void record_external_decl PARAMS ((tree)); > static void warn_if_shadowing PARAMS ((tree, tree)); > static void clone_underlying_type PARAMS ((tree)); >+static int field_decl_cmp PARAMS ((const PTR, const PTR)); > static bool flexible_array_type_p PARAMS ((tree)); > >+ > /* States indicating how grokdeclarator() should handle declspecs marked > with __attribute__((deprecated)). An object declared as > __attribute__((deprecated)) suppresses warnings of uses of other >@@ -4959,6 +4962,27 @@ detect_field_duplicates (tree fieldlist) > } > } > >+/* Function to help qsort sort FIELD_DECLs by name order. */ >+ >+ >+static int >+field_decl_cmp (xp, yp) >+ const PTR xp; >+ const PTR yp; >+{ >+ tree *x = (tree *)xp, *y = (tree *)yp; >+ >+ if (DECL_NAME (*x) == DECL_NAME (*y)) >+ return 0; >+ if (DECL_NAME (*x) == NULL) >+ return -1; >+ if (DECL_NAME (*y) == NULL) >+ return 1; >+ if (DECL_NAME (*x) < DECL_NAME (*y)) >+ return -1; >+ return 1; >+} >+ > /* Fill in the fields of a RECORD_TYPE or UNION_TYPE node, T. > FIELDLIST is a chain of FIELD_DECL nodes for the fields. > ATTRIBUTES are attributes to be applied to the structure. */ >@@ -5162,6 +5186,53 @@ finish_struct (t, fieldlist, 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; >+ char *space; >+ >+ 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) + len * sizeof (tree)); >+ >+ len = 0; >+ field_array = &(((struct lang_type *) space)->elts[0]); >+ for (x = fieldlist; x; x = TREE_CHAIN (x)) >+ { >+ field_array[len++] = x; >+ >+ /* if there is anonymous struct or unoin 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) = (struct lang_type *) space; >+ TYPE_LANG_SPECIFIC (t)->len = len; >+ field_array = &TYPE_LANG_SPECIFIC (t)->elts[0]; >+ 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); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 10962
: 4072 |
4088
|
4118