]> git.ipfire.org Git - thirdparty/autoconf.git/commitdiff
Optimize m4_escape for common case.
authorEric Blake <ebb9@byu.net>
Wed, 28 Oct 2009 17:23:45 +0000 (11:23 -0600)
committerEric Blake <ebb9@byu.net>
Thu, 29 Oct 2009 01:54:01 +0000 (19:54 -0600)
* 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>
ChangeLog
lib/m4sugar/m4sugar.m4

index 41dfb1e973f08b64c130217f1f2477517054e164..a9720393134177a2c0644d73ecfda3078bb43e1e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,10 @@
 2009-10-28  Eric Blake  <ebb9@byu.net>
 
+       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.
+
        Fix m4_text_wrap handling of quoted whitespace.
        * lib/m4sugar/m4sugar.m4 (m4_escape): New macro.
        (m4_text_wrap): Use it to avoid issues with embedded [ and ].
index 6fddff440491f1cb0bd5f6e33573e35814d6c405..e0cacfbdd6e8bae093cbba8b2eb9ed60de9bf0d1 100644 (file)
@@ -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)}>=-)}>=-)}>=-)}>=-)}>=-,