This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFD - cleaning up C identifier lookup
Geoff Keating <geoffk at geoffk dot org> writes:
> Zack Weinberg <zack at codesourcery dot com> writes:
>
>> My suspicion is that block scope external declarations, implicit or
>> explicit, are simply not used in modern C.
>
> I believe this is a reasonable statement, in context. It's not true
> that they're *never* used, but it is true that they're very uncommon.
I mean to instrument GCC and run it on a variety of code to find out
just how uncommon.
>> Thus, we can save two more pointers per identifier by removing both
>> fields and maintaining a global list of such declarations instead;
>> under normal circumstances this list will be empty.
>
> I'm not quite sure how this would work. Would the list only be
> searched when a declaration is seen that is known to be block scope
> external? Or would it need to be searched on *every* decl lookup?
> The first is almost certainly a win, the second maybe not.
It would need to be searched for every declaration with external
linkage. Since the operation is just a walk down a tree_list
comparing pointers, and the list should be short, I don't think it'll
be worse.
>> Second, the distinction between global_value and local_value is
>> artificial. I propose to remove it and use the existing mechanism for
>> block-scope shadows to handle shadowing of globals.
>
> I think this also makes sense, especially if it doesn't add overhead
> unless an identifier is seen that is actually shadowed (which is also
> quite rare).
Right, no additional overhead.
zw