Betreff:   Re: [PATCH 2/2] findutils/grep.c: Short-circuit -v to bail out on
first match
To:        Ari Sundholm <[email protected]>
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 <[email protected]>
> Signed-off-by: Niko Vähäsarja <[email protected]>
> ---
>  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 ?

just my 2 cents

re,
 wh
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to