diff options
author | David Herrmann <dh.herrmann@gmail.com> | 2015-04-17 14:06:31 +0200 |
---|---|---|
committer | David Herrmann <dh.herrmann@gmail.com> | 2015-04-17 15:22:13 +0200 |
commit | 18ae3d98d97ca35da106f66f547bce64b4be31ee (patch) | |
tree | e9dfae626b3e19b0d85c450c89f81ec57e1da4f0 | |
parent | 08232a020bd2571088d3ee06dda07732c5e963d1 (diff) |
sd-device: simplify enumerator hacks
Boolean arithmetic is great, use it!
if (a && !b)
return 1;
if (!a && b)
return -1,
is equivalent to
if (a != b)
return a - b;
Furthermore:
r = false;
if (condition)
r = true;
is equivalent to:
r = condition;
-rw-r--r-- | src/libsystemd/sd-device/device-enumerator.c | 17 |
1 files changed, 5 insertions, 12 deletions
diff --git a/src/libsystemd/sd-device/device-enumerator.c b/src/libsystemd/sd-device/device-enumerator.c index d59da7d88f..4de36d54e1 100644 --- a/src/libsystemd/sd-device/device-enumerator.c +++ b/src/libsystemd/sd-device/device-enumerator.c @@ -273,7 +273,7 @@ int device_enumerator_add_match_is_initialized(sd_device_enumerator *enumerator) static int device_compare(const void *_a, const void *_b) { sd_device *a = (sd_device *)_a, *b = (sd_device *)_b; const char *devpath_a, *devpath_b, *sound_a; - bool delay_a = false, delay_b = false; + bool delay_a, delay_b; assert_se(sd_device_get_devpath(a, &devpath_a) >= 0); assert_se(sd_device_get_devpath(b, &devpath_b) >= 0); @@ -312,17 +312,10 @@ static int device_compare(const void *_a, const void *_b) { } /* md and dm devices are enumerated after all other devices */ - if (strstr(devpath_a, "/block/md") || strstr(devpath_a, "/block/dm-")) - delay_a = true; - - if (strstr(devpath_b, "/block/md") || strstr(devpath_b, "/block/dm-")) - delay_b = true; - - if (delay_a && !delay_b) - return 1; - - if (!delay_a && delay_b) - return -1; + delay_a = strstr(devpath_a, "/block/md") || strstr(devpath_a, "/block/dm-"); + delay_b = strstr(devpath_b, "/block/md") || strstr(devpath_b, "/block/dm-"); + if (delay_a != delay_b) + return delay_a - delay_b; return strcmp(devpath_a, devpath_b); } |