This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: RFD - cleaning up C identifier lookup
Zack Weinberg <zack at codesourcery dot com> writes:
> Geoff Keating <geoffk at geoffk dot org> writes:
>
> > Zack Weinberg <zack at codesourcery dot com> writes:
> >> 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.
One example I saw was that in a header, the programmer had written
something like:
static inline int get_foo1 (void)
{
extern int internal_foo1;
return internal_foo1 + FOO1_BIAS;
}
... (for foo2, foo3, etc., up to maybe foo20, with get & set operations)
presumably so that 'internal_foo1' would be hidden from the user of the
header but still getting the benefits of inlining.
In this case, would the list have 20 elements, or just one? I think
one would still be OK, but 20 might get bad. I don't think more than
one should be needed, since the elements can be (should be) kept out
of the list when they're no longer in scope.
--
- Geoffrey Keating <geoffk at geoffk dot org>