From: Eric Blake Date: Thu, 16 Oct 2008 16:14:09 +0000 (-0600) Subject: Speed up m4_qlen with caching. X-Git-Tag: v2.63b~245 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=257a2a68d02470c252b1183308d9f484a56c8ae6;p=thirdparty%2Fautoconf.git Speed up m4_qlen with caching. * lib/m4sugar/m4sugar.m4 (_m4_qlen): Renamed from old m4_qlen. (m4_qlen): Cache results for speed. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index 8eef61de..dfbbdfd0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2008-10-16 Eric Blake + + Speed up m4_qlen with caching. + * lib/m4sugar/m4sugar.m4 (_m4_qlen): Renamed from old m4_qlen. + (m4_qlen): Cache results for speed. + 2008-10-16 Paolo Bonzini Add a testcase using more then one language. diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 2e02a773..681f4b0d 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -2221,7 +2221,7 @@ dnl either way, insert the word m4_eval(m4_Indent + m4_qlen(_m4_defn([m4_Word])) + 1)) [$2]], [m4_Separator[]])_m4_defn([m4_Word])])]], -dnl finally, clean up the local variabls +dnl finally, clean up the local variables [[_m4_popdef([m4_Separator], [m4_Cursor], [m4_Indent])]])) @@ -2246,12 +2246,19 @@ m4_define([m4_text_box], # --------------- # Expands to the length of STRING after autom4te converts all quadrigraphs. # -# Avoid bpatsubsts for the common case of no quadrigraphs. +# Avoid bpatsubsts for the common case of no quadrigraphs. Cache +# results, as configure scripts tend to ask about lengths of common +# strings like `/*' and `*/' rather frequently. Minimize the number +# of times that $1 occurs in m4_qlen, so there is less text to parse +# on a cache hit. m4_define([m4_qlen], -[m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])], - [m4_len(m4_bpatsubst([[$1]], - [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)], - [\3]))])]) +[m4_ifdef([$0-$1], [_m4_defn([$0-]], [_$0(])[$1])]) +m4_define([_m4_qlen], +[m4_define([m4_qlen-$1], +m4_if(m4_index([$1], [@]), [-1], [m4_len([$1])], + [m4_len(m4_bpatsubst([[$1]], + [@\(\(<:\|:>\|S|\|%:\|\{:\|:\}\)\(@\)\|&t@\)], + [\3]))]))_m4_defn([m4_qlen-$1])]) # m4_qdelta(STRING)