m4-commit
[Top][All Lists]
Advanced

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

[SCM] GNU M4 source repository branch, branch-1.4, updated. v1.4.12-26-g


From: Eric Blake
Subject: [SCM] GNU M4 source repository branch, branch-1.4, updated. v1.4.12-26-g7868936
Date: Thu, 19 Feb 2009 22:48:14 +0000

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 "GNU M4 source repository".

http://git.sv.gnu.org/gitweb/?p=m4.git;a=commitdiff;h=786893619c348defafe09d4653846cf0834e8c86

The branch, branch-1.4 has been updated
       via  786893619c348defafe09d4653846cf0834e8c86 (commit)
      from  29b625aa941718e43cc04dfc217f314518bbc6d1 (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 -----------------------------------------------------------------
commit 786893619c348defafe09d4653846cf0834e8c86
Author: Eric Blake <address@hidden>
Date:   Thu Feb 19 15:39:29 2009 -0700

    Speed up input engine, by searching for quotes by buffer.
    
    * src/input.c (struct input_block): Add end pointer to string.
    (push_string_finish, push_wrapup): Populate it.
    (next_token): For quotes, attempt a buffer search.
    * NEWS: Document this.
    
    Signed-off-by: Eric Blake <address@hidden>

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

Summary of changes:
 ChangeLog   |    6 ++++++
 NEWS        |    2 ++
 src/input.c |   50 +++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 55 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index a80dfea..edff0b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2009-02-18  Eric Blake  <address@hidden>
 
+       Speed up input engine, by searching for quotes by buffer.
+       * src/input.c (struct input_block): Add end pointer to string.
+       (push_string_finish, push_wrapup): Populate it.
+       (next_token): For quotes, attempt a buffer search.
+       * NEWS: Document this.
+
        Speed up translit when from argument is short.
        * m4/gnulib-cache.m4: Import memchr2 module.
        * src/builtin.c (m4_translit): Use memchr2 when possible.
diff --git a/NEWS b/NEWS
index 31821b7..22ea347 100644
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,8 @@ Software Foundation, Inc.
 ** The `translit' builtin has been made more efficient when the second
    argument is short.
 
+** The input engine has been optimized for faster processing.
+
 ** The command line option `--debugfile', introduced in 1.4.7, now
    treats its argument as optional, in order to allow setting the debug
    output back to stderr when used without an argument; and order is now
diff --git a/src/input.c b/src/input.c
index a9471dc..63480be 100644
--- a/src/input.c
+++ b/src/input.c
@@ -1,7 +1,7 @@
 /* GNU m4 -- A simple macro processor
 
    Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 2004, 2005, 2006,
-   2007, 2008 Free Software Foundation, Inc.
+   2007, 2008, 2009 Free Software Foundation, Inc.
 
    This file is part of GNU M4.
 
@@ -23,6 +23,8 @@
 
 #include "m4.h"
 
+#include "memchr2.h"
+
 /* Unread input can be either files, that should be read (eg. included
    files), strings, which should be rescanned (eg. macro expansion text),
    or quoted macro definitions (as returned by the builtin "defn").
@@ -82,6 +84,7 @@ struct input_block
       struct
        {
          char *string;         /* remaining string value */
+         char *end;            /* terminating NUL of string */
        }
        u_s;    /* INPUT_STRING */
       struct
@@ -276,8 +279,10 @@ push_string_finish (void)
 
   if (obstack_object_size (current_input) > 0)
     {
+      size_t len = obstack_object_size (current_input);
       obstack_1grow (current_input, '\0');
       next->u.u_s.string = (char *) obstack_finish (current_input);
+      next->u.u_s.end = next->u.u_s.string + len;
       next->prev = isp;
       isp = next;
       ret = isp->u.u_s.string; /* for immediate use only */
@@ -301,6 +306,7 @@ push_string_finish (void)
 void
 push_wrapup (const char *s)
 {
+  size_t len = strlen (s);
   input_block *i;
   i = (input_block *) obstack_alloc (wrapup_stack,
                                     sizeof (struct input_block));
@@ -308,7 +314,8 @@ push_wrapup (const char *s)
   i->type = INPUT_STRING;
   i->file = current_file;
   i->line = current_line;
-  i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, strlen (s));
+  i->u.u_s.string = (char *) obstack_copy0 (wrapup_stack, s, len);
+  i->u.u_s.end = i->u.u_s.string + len;
   wsp = i;
 }
 
@@ -951,10 +958,47 @@ next_token (token_data *td, int *line)
     }
   else
     {
+      bool fast = lquote.length == 1 && rquote.length == 1;
       quote_level = 1;
       while (1)
        {
-         ch = next_char ();
+         /* Try scanning a buffer first.  */
+         const char *buffer = (isp && isp->type == INPUT_STRING
+                               ? isp->u.u_s.string : NULL);
+         if (buffer && *buffer)
+           {
+             size_t len = isp->u.u_s.end - buffer;
+             const char *p = buffer;
+             do
+               {
+                 p = (char *) memchr2 (p, *lquote.string, *rquote.string,
+                                       buffer + len - p);
+               }
+             while (p && fast && (*p++ == *rquote.string
+                                  ? --quote_level : ++quote_level));
+             if (p)
+               {
+                 if (fast)
+                   {
+                     assert (!quote_level);
+                     obstack_grow (&token_stack, buffer, p - buffer - 1);
+                     isp->u.u_s.string += p - buffer;
+                     break;
+                   }
+                 obstack_grow (&token_stack, buffer, p - buffer);
+                 ch = to_uchar (*p);
+                 isp->u.u_s.string += p - buffer + 1;
+               }
+             else
+               {
+                 obstack_grow (&token_stack, buffer, len);
+                 isp->u.u_s.string += len;
+                 continue;
+               }
+           }
+         /* Fall back to a byte.  */
+         else
+           ch = next_char ();
          if (ch == CHAR_EOF)
            /* current_file changed to "" if we see CHAR_EOF, use
               the previous value we stored earlier.  */


hooks/post-receive
--
GNU M4 source repository




reply via email to

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