summaryrefslogtreecommitdiff
path: root/build-aux/useless-if-before-free
diff options
context:
space:
mode:
authorJán Tomko <jtomko@redhat.com>2016-08-01 10:54:47 -0700
committerJim Meyering <meyering@fb.com>2016-08-02 08:07:40 -0700
commit4f5dc0ac1e08ecc3a2c6eb0e2a8ff526de972b4f (patch)
tree6c86ecb9502a2de0f0c2b6fc62c9155629290408 /build-aux/useless-if-before-free
parentb5f24f6fbfba0afb71ed3707c5be611e287315b7 (diff)
downloadgnulib-4f5dc0ac1e08ecc3a2c6eb0e2a8ff526de972b4f.tar.gz
useless-if-before-free: skip non-matching lines early
* build-aux/useless-if-before-free: First match each line with the simple/quick /\bif\b/ and reject if there is no match. This often saves the cost of the much more involved regular expression. For libvirt, this decreases the cost from 1.44s to 1.02s.
Diffstat (limited to 'build-aux/useless-if-before-free')
-rwxr-xr-xbuild-aux/useless-if-before-free5
1 files changed, 4 insertions, 1 deletions
diff --git a/build-aux/useless-if-before-free b/build-aux/useless-if-before-free
index 1899b1ffd8..d7a8c0dc61 100755
--- a/build-aux/useless-if-before-free
+++ b/build-aux/useless-if-before-free
@@ -4,7 +4,7 @@ eval '(exit $?0)' && eval 'exec perl -wST "$0" "$@"'
# Detect instances of "if (p) free (p);".
# Likewise "if (p != 0)", "if (0 != p)", or with NULL; and with braces.
-my $VERSION = '2016-01-12 23:13'; # UTC
+my $VERSION = '2016-08-01 17:47'; # UTC
# The definition above must lie within the first 8 lines in order
# for the Emacs time-stamp write hook (at end) to update it.
# If you change this file with Emacs, please let the write hook
@@ -129,6 +129,9 @@ sub is_NULL ($)
$err = EXIT_ERROR, next;
while (defined (my $line = <FH>))
{
+ # Skip non-matching lines early to save time
+ $line =~ /\bif\b/
+ or next;
while ($line =~
/\b(if\s*\(\s*([^)]+?)(?:\s*!=\s*([^)]+?))?\s*\)
# 1 2 3