+2007-10-03 Paul Eggert <eggert@cs.ucla.edu>
+
+ * lib/m4sugar/m4sugar.m4 (m4_shift2, m4_shift3): New macros.
+ (m4_shiftn): Remove no-longer-needed optimization. Perhaps we
+ should remove m4_shiftn entirely?
+ (m4_case, b4_bmatch, m4_map_sep, m4_bpatsubsts, m4_join):
+ Prefer m4_shift2 and m4_shift3 to m4_shiftn.
+ * lib/autoconf/lang.m4 (_AC_LANG_DISPATCH): Likewise.
+ * lib/m4sugar/m4sh.m4 (AS_CASE, AS_IF): Likewise.
+ * tests/autotest.at (AT_CHECK_AT_TEST): Likewise.
+
2007-10-03 Eric Blake <ebb9@byu.net>
Comment touchups.
[$#], 1, [ *) $1 ;;],
[$#], 2, [ $1) m4_default([$2], [:]) ;;],
[ $1) m4_default([$2], [:]) ;;
-$0(m4_shiftn(2, $@))])dnl
+$0(m4_shift2($@))])dnl
])
m4_defun([AS_CASE],
[m4_ifval([$2$3],
[m4_ifval([$2$3],
[elif $1; then
m4_default([$2], [:])
-m4_ifval([$3], [$0(m4_shiftn(2, $@))])],
+m4_ifval([$3], [$0(m4_shift2($@))])],
[m4_ifvaln([$1],
[else
$1])dnl
[m4_ifval([$2$3],
[if $1; then
m4_default([$2], [:])
-m4_ifval([$3], [_$0(m4_shiftn(2, $@))])[]dnl
+m4_ifval([$3], [_$0(m4_shift2($@))])[]dnl
fi
])dnl
])# AS_IF
[$#], 1, [],
[$#], 2, [$2],
[$1], [$2], [$3],
- [$0([$1], m4_shiftn(3, $@))])])
+ [$0([$1], m4_shift3($@))])])
# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
[$#], 1, [m4_fatal([$0: too few arguments: $#: $1])],
[$#], 2, [$2],
- [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shiftn(3, $@))],
+ [m4_if(m4_bregexp([$1], [$2]), -1, [$0([$1], m4_shift3($@))],
[$3])])])
# due to quotation problems, I need to double quote $1 below, therefore
# the anchors are broken :( I can't let users be trapped by that.
#
-# Recall that m4_shiftn always results in an argument. Hence, we need
+# Recall that m4_shift3 always results in an argument. Hence, we need
# to distinguish between a final deletion vs. ending recursion.
m4_define([m4_bpatsubsts],
[m4_if([$#], 0, [m4_fatal([$0: too few arguments: $#])],
m4_define([_m4_bpatsubsts],
[m4_if([$#], 2, [$1],
[$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
- m4_shiftn(3, $@))])])
+ m4_shift3($@))])])
# 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_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_assert(0 <= $1 && $1 < $#)dnl
+_m4_shiftn($@)])
m4_define([_m4_shiftn],
[m4_if([$1], 0,
[m4_shift($@)],
[_m4_shiftn(m4_eval([$1]-1), m4_shift(m4_shift($@)))])])
+# m4_shift2(...)
+# m4_shift3(...)
+# -----------------
+# Returns ... shifted twice, and three times. Faster than m4_shiftn.
+m4_define([m4_shift2], [m4_shift(m4_shift($@))])
+m4_define([m4_shift3], [m4_shift(m4_shift(m4_shift($@)))])
# m4_undefine(NAME)
# -----------------
[m4_case([$#],
[1], [],
[2], [[$2]],
- [[$2][$1]$0([$1], m4_shiftn(2, $@))])])
+ [[$2][$1]$0([$1], m4_shift2($@))])])