# [PATCH] remove inline iteration variable

7 messages from 2006-08-15 to 2006-08-17. Participants: David Rientjes, Alex Riesen, Junio C Hamano.
Thread: https://gitlist.dev/t/5285

## David Rientjes, 2006-08-15 17:23

Subject: [PATCH] remove inline iteration variable
Message-ID: <Pine.LNX.4.63.0608151022340.26891@chino.corp.google.com>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0608151022340.26891%40chino.corp.google.com

```
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

```

## Alex Riesen, 2006-08-16 07:27

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <81b0412b0608160027l2ac53c10gd9a75525ca144f1d@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0608160027l2ac53c10gd9a75525ca144f1d%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0608151022340.26891@chino.corp.google.com>

```
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, 2006-08-16 17:14

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <Pine.LNX.4.63.0608161011100.20470@chino.corp.google.com>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0608161011100.20470%40chino.corp.google.com
In-Reply-To: <81b0412b0608160027l2ac53c10gd9a75525ca144f1d@mail.gmail.com>

```
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

```

## Alex Riesen, 2006-08-16 20:10

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <20060816201019.GA6083@steel.home>
URL: https://gitlist.dev/e/20060816201019.GA6083%40steel.home
In-Reply-To: <Pine.LNX.4.63.0608161011100.20470@chino.corp.google.com>

```
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 :)

```

## Junio C Hamano, 2006-08-16 20:16

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <7vzme4307d.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7vzme4307d.fsf%40assigned-by-dhcp.cox.net
In-Reply-To: <20060816201019.GA6083@steel.home>

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

```

## David Rientjes, 2006-08-16 21:41

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <Pine.LNX.4.63.0608161441070.29566@chino.corp.google.com>
URL: https://gitlist.dev/e/Pine.LNX.4.63.0608161441070.29566%40chino.corp.google.com
In-Reply-To: <20060816201019.GA6083@steel.home>

```
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

```

## Alex Riesen, 2006-08-17 09:11

Subject: Re: [PATCH] remove inline iteration variable
Message-ID: <81b0412b0608170211p7289889av43eb7c35ba07fe02@mail.gmail.com>
URL: https://gitlist.dev/e/81b0412b0608170211p7289889av43eb7c35ba07fe02%40mail.gmail.com
In-Reply-To: <Pine.LNX.4.63.0608161441070.29566@chino.corp.google.com>

```
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 :)

```
