This patch speeds up m4 by 20% in its typical use by autoconf. It was tested with the configure script of libtool 1.9b. Before the patch we have the following top 5 functions:
% cumulative self self total time seconds seconds calls s/call s/call name 50.33 26.54 26.54 833006410 0.00 0.00 next_char 43.97 49.73 23.19 12563045 0.00 0.00 next_token 2.09 50.83 1.10 413305 0.00 0.00 expand_token 0.86 51.28 0.46 19684516 0.00 0.00 peek_input 0.75 51.68 0.39 251578 0.00 0.00 expand_user_macro After the patch we have this profile: % cumulative self self total time seconds seconds calls s/call s/call name 91.77 33.86 33.86 12563045 0.00 0.00 next_token 3.01 34.97 1.11 413305 0.00 0.00 expand_token 1.25 35.43 0.46 19684516 0.00 0.00 peek_input 1.15 35.86 0.43 251578 0.00 0.00 expand_user_macro [...] 0.03 36.79 0.01 290882 0.00 0.00 next_char_1 As you can see, 99.9% of all calls to next_char are reading from a string, so we want that case to be fast. In the test case the total runtime decreased from 56 to 44 seconds. Andreas. 2004-09-05 Andreas Schwab <[EMAIL PROTECTED]> * src/input.c (next_char_1): Renamed from next_char. (next_char): New macro. --- src/input.c.~1.1.1.1.~ 2000-02-17 04:03:19.000000000 +0100 +++ src/input.c 2004-09-05 17:44:00.622015557 +0200 @@ -424,10 +424,17 @@ peek_input (void) | they do not get wrong, due to lookahead. The token consisting of a | | newline alone is taken as belonging to the line it ends, and the current | | line number is not incremented until the next character is read. | +| 99.9% of all calls will read from a string, so factor that out into a | +| macro for speed. | `-------------------------------------------------------------------------*/ +#define next_char() \ + (isp && isp->type == INPUT_STRING && isp->u.u_s.string[0] \ + ? *isp->u.u_s.string++ \ + : next_char_1 ()) + static int -next_char (void) +next_char_1 (void) { register int ch; -- Andreas Schwab, SuSE Labs, [EMAIL PROTECTED] SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany Key fingerprint = 58CA 54C7 6D53 942B 1756 01D3 44D5 214B 8276 4ED5 "And now for something completely different." _______________________________________________ Bug-m4 mailing list [EMAIL PROTECTED] http://lists.gnu.org/mailman/listinfo/bug-m4