On Tue, Jul 26, 2016 at 7:28 AM, Ján Tomko <address@hidden> 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(+)
diff --git a/ChangeLog b/ChangeLog
index 64e2026..5aebb2f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2016-07-26 Ján Tomko <address@hidden>
+ useless-if-before-free: skip non-matching lines early
+
+ Check if there is any if keyword on the currently
+ processed line by a simple regex before matching
+ against the more expensive capturing regex.
...
+++ 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 }
Thank you for the patch.
How much of an improvement did this give you?
I ran some quick tests (albeit using \bif\b) and an input file
created with this command run from gnulib source tree:
cat lib/*.c > k; cat k k k k k k k > j; cat j j j j > k
That creates a file with about 127MB on 4 million lines,
and running this script on it prints 1736 lines.
Adding these lines (the syntax I prefer),
$line =~ /\bif\b/
or next;
changed the best-of-10 elapsed run time from 1.50s to 1.35s,
for a 10% (aka 0.15s) speed-up.