grep-commit
[Top][All Lists]
Advanced

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

grep branch, master, updated. v2.27-35-g296f3b9


From: Paul Eggert
Subject: grep branch, master, updated. v2.27-35-g296f3b9
Date: Sun, 1 Jan 2017 00:18:46 +0000 (UTC)

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  296f3b994d59006a64fcd1a2398a6b3e13e84e3c (commit)
      from  bf2b73acf81dd21e7e587dfd00c3362ff412aa46 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=296f3b994d59006a64fcd1a2398a6b3e13e84e3c


commit 296f3b994d59006a64fcd1a2398a6b3e13e84e3c
Author: Paul Eggert <address@hidden>
Date:   Sat Dec 31 16:17:03 2016 -0800

    grep: speed up -x with many patterns
    
    * src/kwsearch.c (Fcompile): Improve buffer allocation overhead
    with -x and multiple patterns.  In the common case where '\n' is
    the end-of-line byte, avoid copying other than the first and last
    patterns.

diff --git a/src/kwsearch.c b/src/kwsearch.c
index fedbe32..a36381f 100644
--- a/src/kwsearch.c
+++ b/src/kwsearch.c
@@ -26,6 +26,8 @@ Fcompile (char const *pattern, size_t size, reg_syntax_t 
ignored)
 {
   kwset_t kwset;
   size_t total = size;
+  char *buf = NULL;
+  size_t bufalloc = 0;
 
   kwset = kwsinit (true);
 
@@ -46,23 +48,32 @@ Fcompile (char const *pattern, size_t size, reg_syntax_t 
ignored)
           total = 0;
         }
 
-      char *buf = NULL;
       if (match_lines)
         {
-          buf = xmalloc (len + 2);
-          buf[0] = eolbyte;
-          memcpy (buf + 1, p, len);
-          buf[len + 1] = eolbyte;
-          p = buf;
+          if (eolbyte == '\n' && pattern < p && sep)
+            p--;
+          else
+            {
+              if (bufalloc < len + 2)
+                {
+                  free (buf);
+                  bufalloc = len + 2;
+                  buf = x2realloc (NULL, &bufalloc);
+                  buf[0] = eolbyte;
+                }
+              memcpy (buf + 1, p, len);
+              buf[len + 1] = eolbyte;
+              p = buf;
+            }
           len += 2;
         }
       kwsincr (kwset, p, len);
-      free (buf);
 
       p = sep;
     }
   while (p);
 
+  free (buf);
   kwsprep (kwset);
 
   return kwset;

-----------------------------------------------------------------------

Summary of changes:
 src/kwsearch.c |   25 ++++++++++++++++++-------
 1 file changed, 18 insertions(+), 7 deletions(-)


hooks/post-receive
-- 
grep



reply via email to

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