[PATCH libinput] evdev: replace null sentinel with ARRAY_SIZE

Dima Ryazanov dima at gmail.com
Wed May 10 15:20:50 UTC 2017


On May 10, 2017 7:14 AM, "Eric Engestrom" <eric.engestrom at imgtec.com> wrote:

Signed-off-by: Eric Engestrom <eric.engestrom at imgtec.com>
---
 src/evdev.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/src/evdev.c b/src/evdev.c
index a2be6fc..7895644 100644
--- a/src/evdev.c
+++ b/src/evdev.c
@@ -50,6 +50,8 @@
 #define DEFAULT_WHEEL_CLICK_ANGLE 15
 #define DEFAULT_BUTTON_SCROLL_TIMEOUT ms2us(200)

+#define ARRAY_SIZE(a) (sizeof(a)/sizeof(a)[0])


I'm guessing this works, but "sizeof(a)[0]" looks very unintuitive to me. I
think "sizeof(a[0])" is the convention?

+
 enum evdev_key_type {
        EVDEV_KEY_TYPE_NONE,
        EVDEV_KEY_TYPE_KEY,
@@ -90,9 +92,6 @@ static const struct evdev_udev_tag_match
evdev_udev_tag_matches[] = {
        {"ID_INPUT_POINTINGSTICK",      EVDEV_UDEV_TAG_POINTINGSTICK},
        {"ID_INPUT_TRACKBALL",          EVDEV_UDEV_TAG_TRACKBALL},
        {"ID_INPUT_SWITCH",             EVDEV_UDEV_TAG_SWITCH},
-
-       /* sentinel value */
-       {0, 0},
 };

 static inline bool
@@ -2373,18 +2372,16 @@ evdev_device_get_udev_tags(struct evdev_device
*device,
                           struct udev_device *udev_device)
 {
        enum evdev_device_udev_tags tags = 0;
-       const struct evdev_udev_tag_match *match;
        int i;

        for (i = 0; i < 2 && udev_device; i++) {
-               match = evdev_udev_tag_matches;
-               while (match->name) {
+               unsigned j;
+               for (j = 0; j < ARRAY_SIZE(evdev_udev_tag_matches); j++) {
+                       const struct evdev_udev_tag_match match =
evdev_udev_tag_matches[j];
                        if (parse_udev_flag(device,
                                            udev_device,
-                                           match->name))
-                               tags |= match->tag;
-
-                       match++;
+                                           match.name))
+                               tags |= match.tag;
                }
                udev_device = udev_device_get_parent(udev_device);
        }
--
Cheers,
  Eric

_______________________________________________
wayland-devel mailing list
wayland-devel at lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/wayland-devel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/wayland-devel/attachments/20170510/08765299/attachment.html>


More information about the wayland-devel mailing list