summaryrefslogtreecommitdiff
path: root/lib/m4sugar/m4sugar.m4
diff options
context:
space:
mode:
authorEric Blake <ebb9@byu.net>2009-10-28 11:23:45 -0600
committerEric Blake <ebb9@byu.net>2009-10-28 19:54:01 -0600
commit820a430f4688f7b374a05c9fa05bcb334321aae4 (patch)
treed2714687b1d92d94b368d51cd0ecdd9aed8a0756 /lib/m4sugar/m4sugar.m4
parent2943c63f52dbed9926a4c87988a0b53c5939679e (diff)
downloadautoconf-820a430f4688f7b374a05c9fa05bcb334321aae4.tar.gz
Optimize m4_escape for common case.
* lib/m4sugar/m4sugar.m4 (m4_escape): Don't use regex if string is already sane, by copying from AS_LITERAL_IF. Move guts... (_m4_escape): ...into new helper. Signed-off-by: Eric Blake <ebb9@byu.net>
Diffstat (limited to 'lib/m4sugar/m4sugar.m4')
-rw-r--r--lib/m4sugar/m4sugar.m416
1 files changed, 16 insertions, 0 deletions
diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4
index 6fddff44..e0cacfbd 100644
--- a/lib/m4sugar/m4sugar.m4
+++ b/lib/m4sugar/m4sugar.m4
@@ -2546,7 +2546,23 @@ m4_define([m4_append_uniq_w],
# -----------------
# Output quoted STRING, but with embedded #, $, [ and ] turned into
# quadrigraphs.
+#
+# It is faster to check if STRING is already good using m4_translit
+# than to blindly perform four m4_bpatsubst.
+#
+# Because the translit is stripping quotes, it must also neutralize
+# anything that might be in a macro name, as well as comments, commas,
+# and parentheses. All the problem characters are unified so that a
+# single m4_index can scan the result.
+#
+# Rather than expand m4_defn every time m4_escape is expanded, we
+# inline its expansion up front.
m4_define([m4_escape],
+[m4_if(m4_index(m4_translit([$1],
+ [[]#,()]]m4_dquote(m4_defn([m4_cr_symbols2]))[, [$$$]), [$]),
+ [-1], [m4_echo], [_$0])([$1])])
+
+m4_define([_m4_escape],
[m4_changequote([-=<{(],[)}>=-])]dnl
[m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(m4_bpatsubst(
-=<{(-=<{(-=<{(-=<{(-=<{($1)}>=-)}>=-)}>=-)}>=-)}>=-,