bug-make
[Top][All Lists]
Advanced

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

Re: AW: AW: address@hidden: "Substitution References" slowdown]


From: psmith
Subject: Re: AW: AW: address@hidden: "Substitution References" slowdown]
Date: Thu, 5 Dec 2002 01:25:13 -0500

%% "Khamenia, Valery" <address@hidden> writes:
 
  >> Ah, OK, I understand now.  I thought this was an example of 
  >> doing it the "fast" way, and the other was an example of doing it 
  >> the slow way. I'll try to generate a test case with similar 
  >> sizes to what you have.

  kv> Thank you a lot, Paul

OK, please apply the following patch.  I reproduced your test case (more
or less) by creating a file with 25,600 lines in it, each of which was a
single word of 150 x's followed by ".ms".  Then I used this makefile:

  FOO := $(shell cat /tmp/x2.txt)

  $(shell date 1>&2)

  BAR := $(FOO:.ms=_blc.log)

  $(shell date 1>&2)

  all: ; @echo hi

On my P4 1.8MHz system at work this took almost three minutes; at home
on my PII 450 it took over 10 minutes!

After I applied the patch it took less than 1 second to run the same
code.  Let me know if you see similar results.

Note this patch is against GNU make 3.80, but it shouldn't be hard to
apply it to 3.79 code.


--- function.c~ 2002-10-23 01:36:49.000000000 -0400
+++ function.c  2002-12-05 01:13:33.000000000 -0500
@@ -87,13 +87,14 @@
      unsigned int slen, rlen;
      int by_word, suffix_only;
 {
-  register char *t = text;
-  register char *p;
+  char *t = text;
+  unsigned int tlen = strlen (text);
+  char *p;
 
   if (slen == 0 && !by_word && !suffix_only)
     {
       /* The first occurrence of "" in any string is its end.  */
-      o = variable_buffer_output (o, t, strlen (t));
+      o = variable_buffer_output (o, t, tlen);
       if (rlen > 0)
        o = variable_buffer_output (o, replace, rlen);
       return o;
@@ -107,11 +108,11 @@
        p = end_of_token (next_token (t));
       else
        {
-         p = sindex (t, 0, subst, slen);
+         p = sindex (t, tlen, subst, slen);
          if (p == 0)
            {
              /* No more matches.  Output everything left on the end.  */
-             o = variable_buffer_output (o, t, strlen (t));
+             o = variable_buffer_output (o, t, tlen);
              return o;
            }
        }
@@ -134,8 +135,12 @@
        /* Output the replacement string.  */
        o = variable_buffer_output (o, replace, rlen);
 
-      /* Advance T past the string to be replaced.  */
-      t = p + slen;
+      /* Advance T past the string to be replaced; adjust tlen.  */
+      {
+        char *nt = p + slen;
+        tlen -= nt - t;
+        t = nt;
+      }
     } while (*t != '\0');
 
   return o;
-- 
-------------------------------------------------------------------------------
 Paul D. Smith <address@hidden>          Find some GNU make tips at:
 http://www.gnu.org                      http://make.paulandlesley.org
 "Please remain calm...I may be mad, but I am a professional." --Mad Scientist

reply via email to

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