This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [RFC/RFA] add struct parse_context to all command functions
>>>>> "Joel" == Joel Brobecker <brobecker@adacore.com> writes:
Joel> I like the idea as well. Just one question: Why did you elect to
Joel> pass the structure as a pointer, rather than the structure
Joel> itself?
To avoid copying. Most users just reference fields from the
structure, or pass it through unmodified. So, this is more efficient
in the common cases.
I would have looked at passing by value if the structure were smaller.
As it is, on my machine it is 68 bytes -- that seems kind of big.
Joel> I wonder if some of the complexity in terms of who owns the
Joel> data, making a copy, etc, could be removed if we passed the
Joel> structure itself. In terms of performance, it shouldn't be a
Joel> problem, as I expect large structs to be passed by reference
Joel> anyway.
I think they have to be copied regardless, though, to preserve
pass-by-value semantics.
In this particular case, ownership is not an issue. These structures
are only ever stack-allocated. Passing pointers to const makes it
clear that these are not mutable.
Stack allocation does make the code a bit uglier, since when we do
want to make a copy we have to give the new object a name. That is
one advantage of pass-by-value.
struct parse_context might be a bit different depending on what you
put in it. For example, I was thinking that lexptr should probably
not be a global. However, if we put it in parse_context, then the
context can't be const. (Maybe we want two different structs though
-- one immutable and one to hold state for a given parse.)
Tom