bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 4/4] useless-if-before-free: skip non-matching lines early


From: Ján Tomko
Subject: Re: [PATCH 4/4] useless-if-before-free: skip non-matching lines early
Date: Mon, 1 Aug 2016 14:11:46 +0200
User-agent: Mutt/1.5.24 (2015-08-30)

On Fri, Jul 29, 2016 at 09:44:11PM -0700, Jim Meyering wrote:
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.


On libvirt code base I get a speed-up from 1.44s to 1.02s.

Jan



reply via email to

[Prev in Thread] Current Thread [Next in Thread]