[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: another m4sugar speedup
From: |
Paul Eggert |
Subject: |
Re: another m4sugar speedup |
Date: |
Wed, 03 Oct 2007 13:09:13 -0700 |
User-agent: |
Gnus/5.11 (Gnus v5.11) Emacs/22.1 (gnu/linux) |
Eric Blake <address@hidden> writes:
> * lib/m4sugar/m4sugar.m4 (m4_shiftn): This macro is called in a
> lot of hot spots; optimize it for 2 and 3 shifts.
Thanks for these optimizations! I installed the following minor
further improvement, which on my host yielded a 3% further speedup for
"autoconf -f" in coreutils.
Perhaps we should get rid of m4_shiftn? Autoconf no longer uses it.
Does anyone else?
2007-10-03 Paul Eggert <address@hidden>
* 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.
diff --git a/lib/autoconf/lang.m4 b/lib/autoconf/lang.m4
index 6532f86..b659b9f 100644
--- a/lib/autoconf/lang.m4
+++ b/lib/autoconf/lang.m4
@@ -83,7 +83,7 @@ m4_define([AC_LANG_CASE],
# unavailable.
m4_define([_AC_LANG_DISPATCH],
[m4_ifdef([$1($2)],
- [m4_indir([$1($2)], m4_shiftn(2, $@))],
+ [m4_indir([$1($2)], m4_shift2($@))],
[AC_FATAL([$1: unknown language: $2])])])
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 6f9e9a6..682a850 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -462,7 +462,7 @@ m4_define([_AS_CASE],
[$#], 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],
@@ -504,7 +504,7 @@ m4_define([_AS_IF],
[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
@@ -514,7 +514,7 @@ m4_defun([AS_IF],
[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
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 4a3a1f7..c835fed 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -362,7 +362,7 @@ m4_define([m4_case],
[$#], 1, [],
[$#], 2, [$2],
[$1], [$2], [$3],
- [$0([$1], m4_shiftn(3, $@))])])
+ [$0([$1], m4_shift3($@))])])
# m4_bmatch(SWITCH, RE1, VAL1, RE2, VAL2, ..., DEFAULT)
@@ -384,7 +384,7 @@ m4_define([m4_bmatch],
[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])])])
@@ -442,7 +442,7 @@ m4_define([m4_map_sep],
# 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: $#])],
@@ -452,7 +452,7 @@ m4_define([m4_bpatsubsts],
m4_define([_m4_bpatsubsts],
[m4_if([$#], 2, [$1],
[$0(m4_builtin([patsubst], [[$1]], [$2], [$3]),
- m4_shiftn(3, $@))])])
+ m4_shift3($@))])])
@@ -560,22 +560,21 @@ 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_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)
# -----------------
@@ -1522,7 +1521,7 @@ m4_defun([m4_join],
[m4_case([$#],
[1], [],
[2], [[$2]],
- [[$2][$1]$0([$1], m4_shiftn(2, $@))])])
+ [[$2][$1]$0([$1], m4_shift2($@))])])
diff --git a/tests/autotest.at b/tests/autotest.at
index 61481f3..b9384f8 100644
--- a/tests/autotest.at
+++ b/tests/autotest.at
@@ -63,7 +63,7 @@ AT_INIT([artificial test suite])
AT_SETUP([my only test])
$2
AT_CLEANUP
-]], m4_shiftn(2, $@))])
+]], m4_shift2($@))])
# Here documents for these tests contain forbidden macros.
m4_pattern_allow([^AT_])
M ChangeLog
M lib/autoconf/lang.m4
M lib/m4sugar/m4sh.m4
M lib/m4sugar/m4sugar.m4
M tests/autotest.at
Committed as 9174b63f95aaf58680bda01f1746dc6f44860a59