In my company's code base there are examples of methods which receive some protobuf messages and use them in this fashion:
void doSomething(const A& a) {
// Only data from a.info() is used in this function. Roughly 4,5 times.
}
Where A is a message type with several (>20) fields and Info also is a message type with several fields.
Shouldn't this syntax be more correct?
void doSomething(const Info& info) {
// Use info in this function
}
I have two concerns:
- From the code practice point of view:
I see that the first syntax allows
doSomethingto be expanded in the future and eventually access some extra information about the message typeA. Shouldn't in that case be more correct to create a different function whenever it will be needed? - From the performance point of view:
I would expect the performance of the two functions to be
comparable, as I am always accessing the
infofield. The overhead would be for the compiler to load in memory the line containinga.info(). Is this correct?
A?