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;
}