From: Eric Blake Date: Wed, 5 Nov 2008 19:09:00 +0000 (-0700) Subject: Use m4_set_map_sep in more places. X-Git-Tag: v2.63b~135 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4e009d522870613c74305ad49e6cc548133b6bab;p=thirdparty%2Fautoconf.git Use m4_set_map_sep in more places. * lib/m4sugar/m4sugar.m4 (m4_set_difference, m4_set_intersection) (m4_set_union): Use m4_set_map_sep rather than m4_set_foreach. * doc/autoconf.texi (Set manipulation Macros) : Enhance documentation. : Mention faster alternative. (Looping constructs) : Likewise. Signed-off-by: Eric Blake --- diff --git a/ChangeLog b/ChangeLog index d14b179f3..73e80955e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,13 @@ 2008-11-05 Eric Blake + Use m4_set_map_sep in more places. + * lib/m4sugar/m4sugar.m4 (m4_set_difference, m4_set_intersection) + (m4_set_union): Use m4_set_map_sep rather than m4_set_foreach. + * doc/autoconf.texi (Set manipulation Macros) : + Enhance documentation. + : Mention faster alternative. + (Looping constructs) : Likewise. + Unify m4_set_foreach and m4_set_map. * lib/m4sugar/m4sugar.m4 (m4_set_map_sep): New macro, undocumented for now. diff --git a/doc/autoconf.texi b/doc/autoconf.texi index bc46d7710..e11499233 100644 --- a/doc/autoconf.texi +++ b/doc/autoconf.texi @@ -10921,6 +10921,9 @@ m4_foreach([myvar], [[foo], [bar, baz]], @result{}echo foo @result{}echo bar, baz @end example + +Note that for some forms of @var{expression}, it may be faster to use +@code{m4_map_args}. @end defmac @anchor{m4_foreach_w} @@ -11786,7 +11789,8 @@ unspecified if @var{action} recursively lists the contents of @var{set} in any way other than removing the element currently contained in @var{variable}. This macro is faster than the corresponding @code{m4_foreach([@var{variable}], -m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])}. +m4_indir([m4_dquote]m4_set_listc([@var{set}])), [@var{action}])}, +although @code{m4_set_map} might be faster still. @example m4_set_add_all([a]m4_for([i], [1], [5], [], [,i])) @@ -11847,9 +11851,11 @@ For each element in the set @var{set}, expand @var{action} with a single argument of the set element. Behavior is unspecified if @var{action} recursively lists the contents of @var{set} (although listing other sets is acceptable), or if it modifies the set in any way other than removing -the element passed as an argument. This macro is faster than the -corresponding -@code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))}. +the element passed as an argument. This macro is faster than either +corresponding counterpart of +@code{m4_map_args([@var{action}]m4_set_listc([@var{set}]))} or +@code{m4_set_foreach([@var{set}], [var], +[@var{action}(m4_defn([var]))])}. @end defmac @defmac m4_set_remove (@var{set}, @var{value}, @ovar{if-present}, @ diff --git a/lib/m4sugar/m4sugar.m4 b/lib/m4sugar/m4sugar.m4 index 15fd80701..5c2e1c80c 100644 --- a/lib/m4sugar/m4sugar.m4 +++ b/lib/m4sugar/m4sugar.m4 @@ -2744,12 +2744,12 @@ m4_define([m4_set_delete], # arguments, such as for m4_join, or wrapped inside quotes for use in # m4_foreach. Order of the output is not guaranteed. # -# Short-circuit the idempotence relation. Use _m4_defn for speed. +# Short-circuit the idempotence relation. m4_define([m4_set_difference], -[m4_if([$1], [$2], [], - [m4_set_foreach([$1], [_m4_element], - [m4_set_contains([$2], _m4_defn([_m4_element]), [], - [,_m4_defn([_m4_element])])])])]) +[m4_if([$1], [$2], [], [m4_set_map_sep([$1], [_$0([$2],], [)])])]) + +m4_define([_m4_set_difference], +[m4_set_contains([$1], [$2], [], [,[$2]])]) # m4_set_dump(SET, [SEP]) # ----------------------- @@ -2814,13 +2814,14 @@ m4_define([m4_set_foreach], # m4_foreach. Order of the output is not guaranteed. # # Iterate over the smaller set, and short-circuit the idempotence -# relation. Use _m4_defn for speed. +# relation. m4_define([m4_set_intersection], [m4_if([$1], [$2], [m4_set_listc([$1])], m4_eval(m4_set_size([$2]) < m4_set_size([$1])), [1], [$0([$2], [$1])], - [m4_set_foreach([$1], [_m4_element], - [m4_set_contains([$2], _m4_defn([_m4_element]), - [,_m4_defn([_m4_element])])])])]) + [m4_set_map_sep([$1], [_$0([$2],], [)])])]) + +m4_define([_m4_set_intersection], +[m4_set_contains([$1], [$2], [,[$2]])]) # m4_set_list(SET) # m4_set_listc(SET) @@ -2901,12 +2902,14 @@ m4_define([_m4_set_size], # not guaranteed. # # We can rely on the fact that m4_set_listc prunes SET1, so we don't -# need to check _m4_set([$1],element) for 0. Use _m4_defn for speed. -# Short-circuit the idempotence relation. +# need to check _m4_set([$1],element) for 0. Short-circuit the +# idempotence relation. m4_define([m4_set_union], -[m4_set_listc([$1])m4_if([$1], [$2], [], [m4_set_foreach([$2], [_m4_element], - [m4_ifdef([_m4_set([$1],]_m4_defn([_m4_element])[)], [], - [,_m4_defn([_m4_element])])])])]) +[m4_set_listc([$1])m4_if([$1], [$2], [], + [m4_set_map_sep([$2], [_$0([$1],], [)])])]) + +m4_define([_m4_set_union], +[m4_ifdef([_m4_set([$1],$2)], [], [,[$2]])]) ## ------------------- ##