m4-patches
[Top][All Lists]
Advanced

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

Re: argv_ref patch 25: allow NUL in quote and comment delimiters


From: Eric Blake
Subject: Re: argv_ref patch 25: allow NUL in quote and comment delimiters
Date: Wed, 18 Jun 2008 21:41:25 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Eric Blake <ebb9 <at> byu.net> writes:

> Phooey - I was timing the wrong build.  In looking at this closer, I'm seeing 
> some noticeable degredation in speed, on the order of 6%; I'm trying to see 
if 
> there is anything obvious that could be causing this slowdown.  My first 
guess 
> is that the MATCH macro in input.c might be the culprit, since it is on a hot 
> path (finding the close-quote to quoted strings).

Good guess, but wrong.  It turns out that I was able to localize the bulk of 
the slowdown to just these four hunks, all of which deal with the replacement 
of hand-rolled obstack output with obstack_printf during stage25.  
obstack_printf is still useful for complex things not on the hot path, but 
looks like it has too much overhead to be used in len, eval, index, and other 
builtins that are frequently called.  I'll be checking in a reversion patch 
based on these four hunks.

diff --git a/src/builtin.c b/src/builtin.c
index 6b107ae..c4a5c58 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -629,7 +629,10 @@ ntoa (int32_t value, int radix)
 static void
 shipout_int (struct obstack *obs, int val)
 {
-  obstack_printf (obs, "%d", val);
+  const char *s;
+
+  s = ntoa ((int32_t) val, 10);
+  obstack_grow (obs, s, strlen (s));
 }
 
 
@@ -1208,14 +1211,11 @@ m4_eval (struct obstack *obs, int argc, macro_arguments 
*argv)
          obstack_1grow (obs, '-');
          value = -value;
        }
-      if ((uint32_t) value < min)
-       {
-         obstack_blank (obs, min - value);
-         memset ((char *) obstack_next_free (obs) - (min - value), '0',
-                 min - value);
-       }
-      obstack_blank (obs, value);
-      memset ((char *) obstack_next_free (obs) - value, '1', value);
+      /* This assumes 2's-complement for correctly handling INT_MIN.  */
+      while (min-- - value > 0)
+       obstack_1grow (obs, '0');
+      while (value-- != 0)
+       obstack_1grow (obs, '1');
       return;
     }
 
@@ -1227,9 +1227,10 @@ m4_eval (struct obstack *obs, int argc, macro_arguments 
*argv)
       s++;
     }
   len = strlen (s);
-  if (min < len)
-    min = len;
-  obstack_printf (obs, "%.*d%s", min - len, 0, s);
+  for (min -= len; --min >= 0;)
+    obstack_1grow (obs, '0');
+
+  obstack_grow (obs, s, len);
 }
 
 static void
diff --git a/src/output.c b/src/output.c
index 6d74ecd..b9b4c9b 100644
--- a/src/output.c
+++ b/src/output.c
@@ -191,7 +191,12 @@ m4_tmpname (int divnum)
   static size_t offset;
   if (buffer == NULL)
     {
-      obstack_printf (&diversion_storage, "%s/m4-", output_temp_dir->dir_name);
+      obstack_grow (&diversion_storage, output_temp_dir->dir_name,
+                   strlen (output_temp_dir->dir_name));
+      obstack_1grow (&diversion_storage, '/');
+      obstack_1grow (&diversion_storage, 'm');
+      obstack_1grow (&diversion_storage, '4');
+      obstack_1grow (&diversion_storage, '-');
       offset = obstack_object_size (&diversion_storage);
       buffer = (char *) obstack_alloc (&diversion_storage,
                                       INT_BUFSIZE_BOUND (divnum));







reply via email to

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