mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Horst von Brand <vonbrand@inf.utfsm.cl>
To: Pavel Machek <pavel@suse.cz>
Cc: domen@coderock.org, linux-kernel@vger.kernel.org
Subject: Re: [patch 2/2] kernel/power/disk.c string fix and if-less iterator
Date: Tue, 21 Jun 2005 11:15:22 -0400	[thread overview]
Message-ID: <200506211515.j5LFFMkJ026010@laptop11.inf.utfsm.cl> (raw)
In-Reply-To: Message from Pavel Machek <pavel@suse.cz>  of "Tue, 21 Jun 2005 00:10:41 +0200." <20050620221041.GI2222@elf.ucw.cz>

Pavel Machek <pavel@suse.cz> wrote:
> domen@coderock.org said:
> > The attached patch:

> > o  Fixes kernel/power/disk.c string declared as 'char *p = "...";' to be
> >    declared as 'char p[] = "...";', as pointed by Jeff Garzik.
> 
> ? Why was char *p ... wrong? Because you could not do sizeof() later?

Note also that this increases the stack usage of the function and slows it
down, as this means allocating an array and filling it in at call time.

> 
> > o  Replaces:
> > 	i++:
> > 	if (i > 3) i = 0;
> > 
> >    By:
> > 	i = (i + 1) % (sizeof(p) - 1);
> > 
> >    Which is if-less, and the adjust value is evaluated by the compiler in
> >    compile-time in case the string related to this loop is modified.
> 
> Well, why not...

Because for that it could be done with a #define of the string... and it is
not that this could change any time soon, so IMHO a constant 3 + comment
would be fine.
-- 
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513

  parent reply	other threads:[~2005-06-21 15:18 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-06-20 21:57 domen
2005-06-20 22:10 ` Pavel Machek
2005-06-20 23:42   ` Andreas Schwab
2005-06-21  7:36   ` Jörn Engel
2005-06-21  9:07   ` Domen Puncer
2005-06-21 15:15   ` Horst von Brand [this message]
2005-06-21  7:33 ` Jörn Engel
2005-06-21 12:18   ` Mitchell Blank Jr

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=200506211515.j5LFFMkJ026010@laptop11.inf.utfsm.cl \
    --to=vonbrand@inf.utfsm.cl \
    --cc=domen@coderock.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pavel@suse.cz \
    /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

all inboxes | Powered by JetHome®