]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic: better readable IN_SET macro
authorMichal Schmidt <mschmidt@redhat.com>
Wed, 22 Jul 2015 15:05:41 +0000 (17:05 +0200)
committerMichal Schmidt <mschmidt@redhat.com>
Wed, 22 Jul 2015 17:29:05 +0000 (19:29 +0200)
Putting the set elements in an array variable and using ELEMENTSOF makes
it clearer what's going on.

Incidentally, it also makes gcc -O2 generate slightly smaller code:
"size systemd", before:
   text    data     bss     dec     hex filename
1378318  128608    2632 1509558  1708b6 systemd

After:
   text    data     bss     dec     hex filename
1377286  128608    2632 1508526  1704ae systemd

src/basic/macro.h

index 5fa17ed2085cdc2fe3a7b992468f5917d6cd96b0..8fae4d0eded250f91eedd97029d4be5df8d9bd03 100644 (file)
@@ -406,12 +406,12 @@ do {                                                                    \
 
 #define IN_SET(x, y, ...)                                               \
         ({                                                              \
-                const typeof(y) _y = (y);                               \
-                const typeof(_y) _x = (x);                              \
+                const typeof(y) _array[] = { (y), __VA_ARGS__ };        \
+                const typeof(y) _x = (x);                               \
                 unsigned _i;                                            \
                 bool _found = false;                                    \
-                for (_i = 0; _i < 1 + sizeof((const typeof(_x)[]) { __VA_ARGS__ })/sizeof(const typeof(_x)); _i++) \
-                        if (((const typeof(_x)[]) { _y, __VA_ARGS__ })[_i] == _x) { \
+                for (_i = 0; _i < ELEMENTSOF(_array); _i++)             \
+                        if (_array[_i] == _x) {                         \
                                 _found = true;                          \
                                 break;                                  \
                         }                                               \