]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Optimize recursion.
authorEric Blake <ebb9@byu.net>
Tue, 2 Oct 2007 21:26:34 +0000 (15:26 -0600)
committerEric Blake <ebb9@byu.net>
Tue, 2 Oct 2007 21:26:34 +0000 (15:26 -0600)
* lib/m4sugar/m4sugar.m4 (m4_shiftn): This macro is called in a
lot of hot spots; optimize it for 2 and 3 shifts.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/m4sugar/m4sugar.m4

index 2dcf677bd4aa8db7e9af272a0e8c3ef4649b6be5..13aa85a7fd393833361e44a7b94e95b6080eea9a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2007-10-02  Eric Blake  <ebb9@byu.net>
 
+       Optimize recursion.
+       * lib/m4sugar/m4sugar.m4 (m4_shiftn): This macro is called in a
+       lot of hot spots; optimize it for 2 and 3 shifts.
+
        Optimize AC_PREREQ and other m4sugar numerics.
        * lib/m4sugar/m4sugar.m4 (m4_sign): Write with m4_eval.
        (m4_cmp): Compare arbitrary expressions, without overflow.
index 2070daab092a8d04956b725e6633a865f585cee7..7b20095144ba427e82a06bff4ebb221138182e41 100644 (file)
@@ -551,9 +551,16 @@ m4_define([m4_noquote],
 # m4_shiftn(N, ...)
 # -----------------
 # Returns ... shifted N times.  Useful for recursive "varargs" constructs.
+#
+# Internally, other m4sugar macros frequently use m4_shiftn(2, $@) and
+# m4_shiftn(3, $@).  Optimize these cases to avoid extra recursion and
+# expansion.
 m4_define([m4_shiftn],
-[m4_assert(($1 >= 0) && ($# > $1))dnl
-_m4_shiftn($@)])
+[m4_if(m4_eval(($1 >= 0) && ($# > $1)), 0,
+         [m4_assert(($1 >= 0) && ($# > $1))],
+       [$1], 2, [m4_shift(m4_shift(m4_shift($@)))],
+       [$1], 3, [m4_shift(m4_shift(m4_shift(m4_shift($@))))],
+       [_m4_shiftn($@)])])
 
 m4_define([_m4_shiftn],
 [m4_if([$1], 0,