git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] remove inline iteration variable
@ 2006-08-15 17:23 David Rientjes
  2006-08-16  7:27 ` Alex Riesen
  0 siblings, 1 reply; 7+ messages in thread
From: David Rientjes @ 2006-08-15 17:23 UTC (permalink / raw)
  To: git

Remove unnecessary iteration variable in inline.

		David

Signed-off-by: David Rientjes <rientjes@google.com>
---
 builtin-grep.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index 93b7e07..6476fe1 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -176,8 +176,8 @@ static void compile_regexp(struct grep_p
 #if DEBUG
 static inline void indent(int in)
 {
-	int i;
-	for (i = 0; i < in; i++) putchar(' ');
+	for (; in > 0; in--)
+		putchar(' ');
 }
 
 static void dump_pattern_exp(struct grep_expr *x, int in)
-- 
1.4.2.rc4.gf615-dirty

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-15 17:23 [PATCH] remove inline iteration variable David Rientjes
@ 2006-08-16  7:27 ` Alex Riesen
  2006-08-16 17:14   ` David Rientjes
  0 siblings, 1 reply; 7+ messages in thread
From: Alex Riesen @ 2006-08-16  7:27 UTC (permalink / raw)
  To: David Rientjes; +Cc: git

On 8/15/06, David Rientjes <rientjes@google.com> wrote:
> Remove unnecessary iteration variable in inline.
> -       for (i = 0; i < in; i++) putchar(' ');
> +       for (; in > 0; in--)

while(in--) putchar(' ');

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-16  7:27 ` Alex Riesen
@ 2006-08-16 17:14   ` David Rientjes
  2006-08-16 20:10     ` Alex Riesen
  0 siblings, 1 reply; 7+ messages in thread
From: David Rientjes @ 2006-08-16 17:14 UTC (permalink / raw)
  To: Alex Riesen; +Cc: git

On Wed, 16 Aug 2006, Alex Riesen wrote:

> On 8/15/06, David Rientjes <rientjes@google.com> wrote:
> > Remove unnecessary iteration variable in inline.
> > -       for (i = 0; i < in; i++) putchar(' ');
> > +       for (; in > 0; in--)
> 
> while(in--) putchar(' ');
> 

That goes into an infinite loop if the argument is negative because it emits a 
cmpl $0, x(%ebp).  Should never happen, but there's no reason not to prevent it 
with a for loop.

		David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-16 17:14   ` David Rientjes
@ 2006-08-16 20:10     ` Alex Riesen
  2006-08-16 20:16       ` Junio C Hamano
  2006-08-16 21:41       ` David Rientjes
  0 siblings, 2 replies; 7+ messages in thread
From: Alex Riesen @ 2006-08-16 20:10 UTC (permalink / raw)
  To: David Rientjes; +Cc: git

David Rientjes, Wed, Aug 16, 2006 19:14:44 +0200:
> > > Remove unnecessary iteration variable in inline.
> > > -       for (i = 0; i < in; i++) putchar(' ');
> > > +       for (; in > 0; in--)
> > 
> > while(in--) putchar(' ');
> > 
> 
> That goes into an infinite loop if the argument is negative because
> it emits a cmpl $0, x(%ebp).  Should never happen, but there's no
> reason not to prevent it with a for loop.

while (in-- > 0) putchar(' ');

still shorter :)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-16 20:10     ` Alex Riesen
@ 2006-08-16 20:16       ` Junio C Hamano
  2006-08-16 21:41       ` David Rientjes
  1 sibling, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2006-08-16 20:16 UTC (permalink / raw)
  To: Alex Riesen; +Cc: git, David Rientjes

fork0@t-online.de (Alex Riesen) writes:

> David Rientjes, Wed, Aug 16, 2006 19:14:44 +0200:
>> > > Remove unnecessary iteration variable in inline.
>> > > -       for (i = 0; i < in; i++) putchar(' ');
>> > > +       for (; in > 0; in--)
>> > 
>> > while(in--) putchar(' ');
>> > 
>> 
>> That goes into an infinite loop if the argument is negative because
>> it emits a cmpl $0, x(%ebp).  Should never happen, but there's no
>> reason not to prevent it with a for loop.
>
> while (in-- > 0) putchar(' ');
>
> still shorter :)

Why do we keep talking about a usually ifdef'ed out debugging
section?

I'll be removing that section altogether ;-).

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-16 20:10     ` Alex Riesen
  2006-08-16 20:16       ` Junio C Hamano
@ 2006-08-16 21:41       ` David Rientjes
  2006-08-17  9:11         ` Alex Riesen
  1 sibling, 1 reply; 7+ messages in thread
From: David Rientjes @ 2006-08-16 21:41 UTC (permalink / raw)
  To: Alex Riesen; +Cc: git

On Wed, 16 Aug 2006, Alex Riesen wrote:

> David Rientjes, Wed, Aug 16, 2006 19:14:44 +0200:
> > > > Remove unnecessary iteration variable in inline.
> > > > -       for (i = 0; i < in; i++) putchar(' ');
> > > > +       for (; in > 0; in--)
> > > 
> > > while(in--) putchar(' ');
> > > 
> > 
> > That goes into an infinite loop if the argument is negative because
> > it emits a cmpl $0, x(%ebp).  Should never happen, but there's no
> > reason not to prevent it with a for loop.
> 
> while (in-- > 0) putchar(' ');
> 
> still shorter :)
> 

It emits a slightly rearranged assembly with the same number of instructions.

		David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH] remove inline iteration variable
  2006-08-16 21:41       ` David Rientjes
@ 2006-08-17  9:11         ` Alex Riesen
  0 siblings, 0 replies; 7+ messages in thread
From: Alex Riesen @ 2006-08-17  9:11 UTC (permalink / raw)
  To: David Rientjes; +Cc: git

On 8/16/06, David Rientjes <rientjes@google.com> wrote:
> > > > > Remove unnecessary iteration variable in inline.
> > > > > -       for (i = 0; i < in; i++) putchar(' ');
> > > > > +       for (; in > 0; in--)
> > > >
> > > > while(in--) putchar(' ');
> > > >
> > >
> > > That goes into an infinite loop if the argument is negative because
> > > it emits a cmpl $0, x(%ebp).  Should never happen, but there's no
> > > reason not to prevent it with a for loop.
> >
> > while (in-- > 0) putchar(' ');
> >
> > still shorter :)
> >
>
> It emits a slightly rearranged assembly with the same number of instructions.
>

oops. I should've looked at the output. But the point moot anyway, Junio says :)

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2006-08-17  9:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-15 17:23 [PATCH] remove inline iteration variable David Rientjes
2006-08-16  7:27 ` Alex Riesen
2006-08-16 17:14   ` David Rientjes
2006-08-16 20:10     ` Alex Riesen
2006-08-16 20:16       ` Junio C Hamano
2006-08-16 21:41       ` David Rientjes
2006-08-17  9:11         ` Alex Riesen

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).