[PATCH 2/2] findutils/grep.c: Short-circuit -v to bail out on first match
Walter Harms
wharms at bfs.de
Mon Jan 28 16:11:41 UTC 2019
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 ?
just my 2 cents
re,
wh
More information about the busybox
mailing list