basic: more optimizable IN_SET macro

Making the array static allows gcc -O2 to generate smaller code:

"size systemd" before:
   text    data     bss     dec     hex filename
1377286  128608    2632 1508526  1704ae systemd

After:
   text    data     bss     dec     hex filename
1374326  128572    2664 1505562  16f91a systemd

(IN_SET still results in worse generated code than using
 "x == FOO || x == BAR || ...". I don't think we'll be able to match
 that with the C preprocessor.)

This change limits the use of IN_SET to sets with constant elements. All
present callers use constants. The compiler would report an "initializer
element is not constant" error otherwise.
This commit is contained in:
Michal Schmidt 2015-07-22 17:50:44 +02:00
parent 249a2737ba
commit 77247cba3e

View file

@ -406,7 +406,7 @@ do { \
#define IN_SET(x, y, ...) \
({ \
const typeof(y) _array[] = { (y), __VA_ARGS__ }; \
static const typeof(y) _array[] = { (y), __VA_ARGS__ }; \
const typeof(y) _x = (x); \
unsigned _i; \
bool _found = false; \