[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
faster _AS_QUOTE
From: |
Eric Blake |
Subject: |
faster _AS_QUOTE |
Date: |
Thu, 20 Nov 2008 19:39:51 +0000 (UTC) |
User-agent: |
Loom/3.14 (http://gmane.org/) |
Low-hanging fruit. _AS_QUOTE is a core part of AC_MSG_WARN and AC_MSG_ERROR
(aka AS_WARNING and AS_ERROR). The old implementation was passing 13 copies of
the detail string through m4_cond, which itself is a somewhat heavyweight macro
at repeatedly reparsing its input. This trims thing down, so that m4_cond only
sees 3 copies of the detail string; the effect was >1% speedup of autoconf on
coreutils configure.ac.
From: Eric Blake <address@hidden>
Date: Thu, 20 Nov 2008 12:08:14 -0700
Subject: [PATCH] Speed up _AS_QUOTE.
* lib/m4sugar/m4sh.m4 (_AS_QUOTE_IFELSE): Inline into...
(_AS_QUOTE): ...here, delete unused second paramenter, and factor
choice into...
(_AS_QUOTE_MODERN, _AS_QUOTE_OLD): ...new helpers.
Signed-off-by: Eric Blake <address@hidden>
---
ChangeLog | 8 ++++++++
lib/m4sugar/m4sh.m4 | 38 ++++++++++++++++++--------------------
2 files changed, 26 insertions(+), 20 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 10bd336..22c98d0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2008-11-20 Eric Blake <address@hidden>
+
+ Speed up _AS_QUOTE.
+ * lib/m4sugar/m4sh.m4 (_AS_QUOTE_IFELSE): Inline into...
+ (_AS_QUOTE): ...here, delete unused second paramenter, and factor
+ choice into...
+ (_AS_QUOTE_MODERN, _AS_QUOTE_OLD): ...new helpers.
+
2008-11-20 Alfred G. de Wijn <address@hidden> (tiny change)
For consistency, make temporary variable match language name.
diff --git a/lib/m4sugar/m4sh.m4 b/lib/m4sugar/m4sh.m4
index 8863c82..0b32440 100644
--- a/lib/m4sugar/m4sh.m4
+++ b/lib/m4sugar/m4sh.m4
@@ -669,8 +669,11 @@ m4_define([_AS_ESCAPE],
[$1], [m4_bpatsubst([$1], [[$2]], [\\\&])])])
-# _AS_QUOTE_IFELSE(STRING, IF-MODERN-QUOTATION, IF-OLD-QUOTATION)
-# ---------------------------------------------------------------
+# _AS_QUOTE(STRING)
+# -----------------
+# If there are quoted (via backslash) backquotes, output STRING
+# literally and warn; otherwise, output STRING with ` and " quoted.
+#
# Compatibility glue between the old AS_MSG suite which did not
# quote anything, and the modern suite which quotes the quotes.
# If STRING contains `\\' or `\$', it's modern.
@@ -685,25 +688,20 @@ m4_define([_AS_ESCAPE],
# [$2])
# The current implementation caters to the common case of no backslashes,
# to minimize m4_index expansions (hence the nested if).
-m4_define([_AS_QUOTE_IFELSE],
-[m4_cond([m4_index([$1], [\])], [-1], [$2],
- [m4_eval(m4_index([$1], [\\]) >= 0)], [1], [$2],
- [m4_eval(m4_index([$1], [\$]) >= 0)], [1], [$2],
- [m4_eval(m4_index([$1], [\`]) >= 0)], [1], [$3],
- [m4_eval(m4_index([$1], [\"]) >= 0)], [1], [$3],
- [$2])])
-
-
-# _AS_QUOTE(STRING, [CHARS = `"])
-# -------------------------------
-# If there are quoted (via backslash) backquotes do nothing, else
-# backslash all the quotes.
m4_define([_AS_QUOTE],
-[_AS_QUOTE_IFELSE([$1],
- [_AS_ESCAPE([$1], m4_default([$2], [`""]))],
- [m4_warn([obsolete],
- [back quotes and double quotes must not be escaped in: $1])dnl
-$1])])
+[m4_cond([m4_index([$1], [\])], [-1], [_AS_QUOTE_MODERN],
+ [m4_eval(m4_index(m4_translit([[$1]], [$], [\]), [\\]) >= 0)],
+[1], [_AS_QUOTE_MODERN],
+ [m4_eval(m4_index(m4_translit([[$1]], ["], [`]), [\`]) >= 0)],dnl"
+[1], [_AS_QUOTE_OLD],
+ [_AS_QUOTE_MODERN])([$1])])
+
+m4_define([_AS_QUOTE_MODERN],
+[_AS_ESCAPE([$1], [`""])])
+
+m4_define([_AS_QUOTE_OLD],
+[m4_warn([obsolete],
+ [back quotes and double quotes must not be escaped in: $1])$1])
# _AS_ECHO_UNQUOTED(STRING, [FD = AS_MESSAGE_FD])
--
1.6.0.4
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- faster _AS_QUOTE,
Eric Blake <=