From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Anshul Garg <aksgarg1989@gmail.com>
Cc: linux-input@vger.kernel.org
Subject: Re: [PATCH] Input: Use for_each_set_bit where appropriate
Date: Thu, 9 Jul 2015 10:26:30 -0700 [thread overview]
Message-ID: <20150709172630.GA1237@dtor-ws> (raw)
In-Reply-To: <1436449261-66742-1-git-send-email-aksgarg1989@gmail.com>
On Thu, Jul 09, 2015 at 06:41:01AM -0700, Anshul Garg wrote:
> Use for_each_set_bit to check for set bits in bitmap
> as it is more efficient and compact.
> Also use bitwise and instead of expensive %
> operation while fetching next event.
It is not expensive if we are using a constant that is carefully
selected (and it is).
>
> Signed-off-by: Anshul Garg <aksgarg1989@gmail.com>
> ---
> drivers/input/misc/uinput.c | 11 ++++-------
> 1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
> index 421e29e..a3c15ad 100644
> --- a/drivers/input/misc/uinput.c
> +++ b/drivers/input/misc/uinput.c
> @@ -319,11 +319,8 @@ static int uinput_validate_absbits(struct input_dev *dev)
> /*
> * Check if absmin/absmax/absfuzz/absflat are sane.
> */
> -
> - for (cnt = 0; cnt < ABS_CNT; cnt++) {
> + for_each_set_bit(cnt, dev->absbit, ABS_CNT) {
> int min, max;
> - if (!test_bit(cnt, dev->absbit))
> - continue;
>
> min = input_abs_get_min(dev, cnt);
> max = input_abs_get_max(dev, cnt);
> @@ -415,8 +412,8 @@ static int uinput_setup_device(struct uinput_device *udev,
> dev->id.vendor = user_dev->id.vendor;
> dev->id.product = user_dev->id.product;
> dev->id.version = user_dev->id.version;
> -
> - for (i = 0; i < ABS_CNT; i++) {
> +
> + for_each_set_bit(i, dev->absbit, ABS_CNT) {
> input_abs_set_max(dev, i, user_dev->absmax[i]);
> input_abs_set_min(dev, i, user_dev->absmin[i]);
> input_abs_set_fuzz(dev, i, user_dev->absfuzz[i]);
> @@ -493,7 +490,7 @@ static bool uinput_fetch_next_event(struct uinput_device *udev,
> have_event = udev->head != udev->tail;
> if (have_event) {
> *event = udev->buff[udev->tail];
> - udev->tail = (udev->tail + 1) % UINPUT_BUFFER_SIZE;
> + udev->tail &= UINPUT_BUFFER_SIZE - 1;
What is this exactly? And how did you test it?
This chunk dropped form the patch.
Thanks.
--
Dmitry
next prev parent reply other threads:[~2015-07-09 17:26 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-09 13:41 [PATCH] Input: Use for_each_set_bit where appropriate Anshul Garg
2015-07-09 17:26 ` Dmitry Torokhov [this message]
2015-07-09 17:35 ` Anshul Garg
2015-07-09 18:14 ` Dmitry Torokhov
2015-07-09 18:17 ` Anshul Garg
-- strict thread matches above, loose matches on Subject: below --
2015-07-08 18:08 Anshul Garg
2015-09-17 20:02 ` Stephen Chandler Paul
2015-09-19 18:26 ` Dmitry Torokhov
2015-09-21 14:30 ` Stephen Chandler Paul
2015-09-21 22:58 ` Dmitry Torokhov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150709172630.GA1237@dtor-ws \
--to=dmitry.torokhov@gmail.com \
--cc=aksgarg1989@gmail.com \
--cc=linux-input@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.