Subject: Re: bug#17143: [PATCH] grep: speed-up for line matching in fgrep

From: Paolo Bonzini <[email-masked]>
Date: Tue, 01 Apr 2014 10:45:12 +0200

Il 30/03/2014 14:14, Norihiro Tanaka ha scritto:
> -          if (beg > buf && beg[-1] != eol)
> -            continue;
> -          if (beg + len < buf + size && beg[len] != eol)
> -            continue;
> -          goto success;
> +          if (beg[-1] == eol && beg[len] == eol)
> +            goto success;
> +          beg = memchr (beg, eol, buf + size - beg);
>          }

Are we sure that beg > buf && beg + len < buf + size?

Perhaps we need

   if (beg > buf && beg[-1] == eol &&
       beg + len < buf + size && beg[len] == eol)
     goto success;

   beg = memchr (beg, eol, buf + size - beg);

Otherwise, the patch is an obvious improvement.  Thanks!

Paolo