m4-discuss
[Top][All Lists]
Advanced

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

Re: next_char inlining (was: Re: M4 1.4.10b [beta] released)


From: Bruno Haible
Subject: Re: next_char inlining (was: Re: M4 1.4.10b [beta] released)
Date: Fri, 29 Feb 2008 11:31:33 +0100
User-agent: KMail/1.5.4

| The speed-relevant code is only the case for INPUT_CHAIN. I added the one
| for INPUT_STRING because it may be useful it situations I don't know of.

And here is, for completeness, the handling of INPUT_FILE. It requires the
modules freadahead, freadptr, freadseek from gnulib. No speed improvement
measureable with autoconf.

*** input.c.patch11     2008-02-28 14:52:02.000000000 +0100
--- input.c     2008-02-29 01:53:41.000000000 +0100
***************
*** 60,65 ****
--- 60,69 ----
     swapping between input blocks updates the global variables
     accordingly.  */
  
+ #include "freadahead.h"
+ #include "freadptr.h"
+ #include "freadseek.h"
+ 
  #ifdef ENABLE_CHANGEWORD
  # include "regex.h"
  #endif /* ENABLE_CHANGEWORD */
***************
*** 1733,1738 ****
--- 1737,1799 ----
                      continue;
                    }
                }
+             else if (isp->type == INPUT_FILE)
+               {
+                 if (!isp->u.u_f.end)
+                   {
+                     size_t n = freadahead (isp->u.u_f.fp);
+                     if (n > 0)
+                       {
+                         const char *readptr = freadptr (isp->u.u_f.fp);
+                         if (readptr != NULL)
+                           {
+                             unsigned char curr_quote_1 =
+                               to_uchar (curr_quote.str1[0]);
+                             unsigned char curr_quote_2 =
+                               to_uchar (curr_quote.str2[0]);
+                             const char *p = readptr;
+                             size_t count;
+ 
+                             do
+                               {
+                                 unsigned char ch;
+ 
+                                 if (start_of_input_line)
+                                   {
+                                     start_of_input_line = false;
+                                     current_line = ++isp->line;
+                                   }
+                                 ch = to_uchar (*p);
+                                 if (ch == '\n')
+                                   start_of_input_line = true;
+                                 if (ch == curr_quote_2)
+                                   {
+                                     if (--quote_level == 0)
+                                       break;
+                                   }
+                                 else
+                                   quote_level += (ch == curr_quote_1);
+                                 p++;
+                                 n--;
+                               }
+                             while (n > 0);
+ 
+                             count = p - readptr;
+                             if (count > 0)
+                               obstack_grow (obs_td, readptr, count);
+                             count += (quote_level == 0);
+                             assert (count > 0);
+                             if (freadseek (isp->u.u_f.fp, count) < 0)
+                               /* freadseek should not fail, since
+                                  count <= freadahead (isp->u.u_f.fp).  */
+                               abort ();
+                             if (quote_level == 0)
+                               break;
+                             continue;
+                           }
+                       }
+                   }
+               }
            }
  
          /* The general case.  Proceed character by character.  */





reply via email to

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