[PATCH 2/2] findutils/grep.c: Short-circuit -v to bail out on first match

Ari Sundholm ari at tuxera.com
Mon Jan 28 17:21:29 UTC 2019


On 1/28/19 6:11 PM, Walter Harms wrote:
> Betreff:   Re: [PATCH 2/2] findutils/grep.c: Short-circuit -v to bail out on
> first match
> To:        Ari Sundholm <ari at tuxera.com>
> Cc:
> Bcc:
> -=-=-=-=-=-=-=-=-=# Diese Zeile unbedingt stehen lassen - unterhalb beginnen Sie
> Ihren Mailtext #=-=-=-=-=-=-=-=-=-
> 
> 
> Am 28.01.2019 16:11, schrieb Ari Sundholm:
>> A small optimization. There is no need to try matching the current
>> input line against any further patterns if a match was already
>> found and -v is specified.
>>
>> Signed-off-by: Ari Sundholm <ari at tuxera.com>
>> Signed-off-by: Niko Vähäsarja <niko at tuxera.com>
>> ---
>>   findutils/grep.c | 3 +++
>>   1 file changed, 3 insertions(+)
>>
>> diff --git a/findutils/grep.c b/findutils/grep.c
>> index 9d9da422c..6abefffdc 100644
>> --- a/findutils/grep.c
>> +++ b/findutils/grep.c
>> @@ -447,6 +447,9 @@ static int grep_file(FILE *file)
>>   			 * at first match */
>>   			if (found && !invert_search)
>>   				goto do_found;
>> +			else if (invert_search && found)
>> +				break;
>> +
>>   			pattern_ptr = pattern_ptr->link;
>>   		} /* while (pattern_ptr) */
>>   
> 
> maybe
> 
> if (found) {
>     if (invert_search)
>          break;
>     else
>          goto do_found;
> }
> 
> is more easy to read ?
> 

Indeed. I think the comment above the if should also be updated. I'll 
submit a v2 soon.

Thank you,
Ari Sundholm
ari at tuxera.com

> just my 2 cents
> 
> re,
>   wh
> 



More information about the busybox mailing list