From 7571dc49e5237830ba53a1fe9156d56ef15ba6ee Mon Sep 17 00:00:00 2001 From: Thilo Schulz Date: Sun, 1 Feb 2015 15:58:36 +0100 Subject: [PATCH] Use memcpy/memmove instead of loop operations Signed-off-by: Thilo Schulz Signed-off-by: Peter Hutterer --- libevdev/libevdev-int.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libevdev/libevdev-int.h b/libevdev/libevdev-int.h index 5e5ab26..372db53 100644 --- a/libevdev/libevdev-int.h +++ b/libevdev/libevdev-int.h @@ -193,22 +193,21 @@ queue_peek(struct libevdev *dev, size_t idx, struct input_event *ev) static inline int queue_shift_multiple(struct libevdev *dev, size_t n, struct input_event *ev) { - size_t i; + size_t remaining; if (dev->queue_next == 0) return 0; - n = min(n, dev->queue_next); + remaining = dev->queue_next; + n = min(n, remaining); + remaining -= n; - if (ev) { - for (i = 0; i < n; i++) - ev[i] = dev->queue[i]; - } + if (ev) + memcpy(ev, dev->queue, n * sizeof(*ev)); - for (i = 0; i < dev->queue_next - n; i++) - dev->queue[i] = dev->queue[n + i]; + memmove(dev->queue, &dev->queue[n], remaining * sizeof(*dev->queue)); - dev->queue_next -= n; + dev->queue_next = remaining; return n; } -- 2.7.4