netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick McHardy <kaber@trash.net>
To: Stephen Hemminger <shemminger@vyatta.com>
Cc: David Miller <davem@davemloft.net>, netdev@vger.kernel.org
Subject: Re: [PATCH 2/4] dsmark: get rid of trivial function
Date: Mon, 21 Jan 2008 01:16:32 +0100	[thread overview]
Message-ID: <4793E460.5020804@trash.net> (raw)
In-Reply-To: <20080120132550.056370c0@deepthought>

Stephen Hemminger wrote:
> Replace loop in dsmark_valid_indices with equivalent bit math.
> 
> Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
> 
> --- a/net/sched/sch_dsmark.c	2008-01-20 13:07:58.000000000 -0800
> +++ b/net/sched/sch_dsmark.c	2008-01-20 13:22:54.000000000 -0800
> @@ -45,13 +45,8 @@ struct dsmark_qdisc_data {
>  
>  static inline int dsmark_valid_indices(u16 indices)
>  {
> -	while (indices != 1) {
> -		if (indices & 1)
> -			return 0;
> -		indices >>= 1;
> -	}
> -
> -	return 1;
> +	/* Must have only one bit set */
> +	return (indices & (indices - 1)) == 0;


hweight seems easier to understand, it took me a bit
to realize that the comment matches the code :)

  reply	other threads:[~2008-01-21  0:16 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20080120130542.16720b45@deepthought>
2008-01-20 21:25 ` [PATCH 2/4] dsmark: get rid of trivial function Stephen Hemminger
2008-01-21  0:16   ` Patrick McHardy [this message]
2008-01-21  8:39     ` Ilpo Järvinen
2008-01-21 10:22     ` David Miller
2008-01-22  3:47       ` Stephen Hemminger
2008-01-22  3:59         ` David Miller

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=4793E460.5020804@trash.net \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=shemminger@vyatta.com \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).