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.

Signed-off-by: Eric Blake <ebb9@byu.net>
This commit is contained in:
Eric Blake 2007-10-02 15:26:34 -06:00
parent 7113f1b07c
commit 57e51969f0
2 changed files with 13 additions and 2 deletions

View File

@ -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.

View 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,