On 07/26/2016 08:28 AM, Ján Tomko wrote:
> Check if there is any if keyword on the currently
> processed line by a simple regex before matching
> against the more expensive capturing regex.
> ---
>  ChangeLog                        | 8 ++++++++
>  build-aux/useless-if-before-free | 3 +++
>  2 files changed, 11 insertions(+)
> 

> +++ b/build-aux/useless-if-before-free
> @@ -129,6 +129,9 @@ sub is_NULL ($)
>            $err = EXIT_ERROR, next;
>        while (defined (my $line = <FH>))
>          {
> +          # Skip non-matching lines early to save time
> +          if (not $line =~ /\bif/) { next }

Do you want \bif\b, so as to avoid false positives on 'ifelse' or other
non-keywords with a common prefix?

> +
>            while ($line =~
>                /\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\)
>                #  1          2                  3
> 

At any rate, this optimization makes total sense.

-- 
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to