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.
# 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,