threads / patch / 5285

patchremove inline iteration variable

Subject: [PATCH] remove inline iteration variable

## tl;dr

7 messages between Aug 15, 2006 and Aug 17, 2006. Diffs are folded; open one to read it.

replies: 6people: 3as markdown or json

David Rientjes· Aug 15, 2006, 17:23 UTC · lore
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(-)
Show changes to builtin-grep.c +2 −2
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
Alex Riesen· Aug 16, 2006, 07:27 UTC · re: David Rientjes · lore

Re: [PATCH] remove inline iteration variable

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(' ');
David Rientjes· Aug 16, 2006, 17:14 UTC · re: Alex Riesen · lore

Re: [PATCH] remove inline iteration variable

On Wed, 16 Aug 2006, Alex Riesen wrote:
Show 7 quoted lines
> 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
Alex Riesen· Aug 16, 2006, 20:10 UTC · re: David Rientjes · lore

Re: [PATCH] remove inline iteration variable

David Rientjes, Wed, Aug 16, 2006 19:14:44 +0200:
Show 10 quoted lines
> > > 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 :)
Junio C Hamano· Aug 16, 2006, 20:16 UTC · re: Alex Riesen · lore

Re: [PATCH] remove inline iteration variable

fork0@t-online.de (Alex Riesen) writes:
Show 15 quoted lines
> 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 ;-).
David Rientjes· Aug 16, 2006, 21:41 UTC · re: Alex Riesen · lore

Re: [PATCH] remove inline iteration variable

On Wed, 16 Aug 2006, Alex Riesen wrote:
Show 16 quoted lines
> 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
Alex Riesen· Aug 17, 2006, 09:11 UTC · re: David Rientjes · lore

Re: [PATCH] remove inline iteration variable

On 8/16/06, David Rientjes <rientjes@google.com> wrote:
Show 18 quoted lines
> > > > > 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 :)

← back to recent threads