On 2024/8/28 11:22, Andrew Morton wrote:
On Wed, 28 Aug 2024 09:48:21 +0800 Hongbo Li <[email protected]> wrote:

This might result in copies of the strings "true" and "false" being
generated for every .c file which uses this function, resulting in
unnecessary bloat.

It's possible that the compiler/linker can eliminate this duplication.
If not, I suggest that every function in string_choices.h be uninlined.
The inline function is in header file, it will cause code expansion. It
should avoid the the copies of the strings.

Sorry, I don't understand your reply.

I mean this is a inline function (and tiny enough), the compiler will do the code expansion and some optimizations.
Anything which is calling these functions is not performance-sensitive,
so optimizing for space is preferred.  An out-of-line function which
returns a const char * will achieve this?
I think this helper can achieve this. Because it is tiny enough, the compiler will handle this like #define macro (do the replacement) without allocating extra functional stack. On the contrary, if it is implemented as a non-inline function, it will cause extra functional stack when it was called every time. And it also should be implemented in a source file (.c file), not in header file(.h file).

Thanks,
Hongbo

Reply via email to