From b2dda0adc778b0d3004950048211289958da2abc Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 29 Sep 2007 21:44:10 -0600
Subject: [PATCH] Speed optimization: avoid m4 regex when other
algorithms work.
* lib/m4sugar/m4sh.m4 (AS_LITERAL_IF): Rewrite without regex.
(_AS_QUOTE_IFELSE): Likewise.
* lib/m4sugar/m4sugar.m4 (m4_strip): Reduce from 3 to 2 regex.
(m4_bpatsubsts): Split...
(_m4_bpatsubsts): ...so that recursion can avoid patsubst on empty
regex.
(_m4_divert()): Define, to avoid m4 warning on `m4_divert'.
(m4_qlen): Optimize on short strings, to avoid regex.
(m4_sign): Avoid regex, and fix bug with `01' and `-0'.
* lib/autoconf/general.m4 (AC_CACHE_VAL): Rewrite without regex.
(AC_DEFINE_TRACE): Likewise.
Signed-off-by: Eric Blake <address@hidden>
#
-# Then notice the 2 last patterns: they are in charge of removing the
+# First, notice that we guarantee trailing space. Why? Because
regex
+# are greedy, and `.* ?' always groups the space into the .* portion.
+# The algorithm is simpler by avoiding `?' at the end. The algorithm
+# correctly strips everything if STRING is just ` '.
+#
+# Then notice the second pattern: it is in charge of removing the
# leading/trailing spaces. Why not just `[^ ]'? Because they are
-# applied to doubly quoted strings, i.e. more or less [[STRING]]. So
-# if there is a leading space in STRING, then it is the *third*
-# character, since there are two leading `['; equally for the last
pattern.
+# applied to over-quoted strings, i.e. more or less [STRING], due
+# to the limitations of m4_bpatsubsts. So the leading space in
STRING
+# is the *second* character; equally for the trailing space.
m4_define([m4_strip],
-[m4_bpatsubsts([[$1]],
+[m4_bpatsubsts([$1 ],
[[ ]+], [ ],
- [^\(..\) ], [\1],
- [ \(..\)$], [\1])])
+ [^. ?\(.*\) .$], [[[\1]]])])