Skip to content

WIP: [RFC] wire up a tp_for_each_touch_skip

Konstantin Kharlamov requested to merge Hi-Angel/libinput:skip_none_macro into master

So, this is an idea I've had for a long time. Almost every tp_for_each_touch in the code currently does an additional check for the touch, and then skips them. Would be nice to have a similar macro, which would allow to move the condition inside it.

This is an RFC because there're lots of such places in the code, and I wanted to hear if there be any opposition before doing the work. The commit in the MR adds a tp_for_each_touch_skip (and a macro helper) and converts one such place at evdev-mt-touchpad.c:1730.

I use __extension__ keyword for one of the macros — as far as I can see libinput uses std=gnuXX standard, so I assume this is allowed.

I also invert the condition (i.e. in evdev-mt-touchpad.c:1730 the if (t->state == TOUCH_NONE) continue; became a condition t->state != TOUCH_NONE) because when I re-read the code, it seemed more like the condition says "what elements to pick" rather than "what elements to skip". But that may be subjective, ideas are welcome.

Performance: funny thing, upon building with -O3 when I compare code size of the object file before and after my patch, it is actually a tiny bit smaller: 448472 before and 446496 after. This is with gcc 10.2.0. I assume the reason is that my implementation of the foreach does not use indices. I'd expect optimizer to produce the same code, but oh well… At least it became better, not worse :) Nvm, I just figured, it was because of debug information. After I stripped object files, they both have the same size of 35832.

Edited by Peter Hutterer

Merge request reports