libtool-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

optimize lt_combine


From: Eric Blake
Subject: optimize lt_combine
Date: Wed, 17 Oct 2007 18:25:38 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

I liked the concept of lt_combine so much that I added m4_combine to m4sugar.  
In the process, I made some optimizations and some slight semantic changes:

 - the separator is now used literally, rather than losing whitespace after 
comma
 - the infix argument is now used literally, rather than undergoing expansion 
(consider m4_define([_],[oops])...)
 - the quoting in m4_foreach is fixed (consider m4_define([_Lt_suffix])...)
 - useless use of m4_car is avoided, and the m4_shiftn(3, $@) is now inlined 
and done once up front, rather than once per _Lt_prefix
 - the separator is no longer defaulted, so you can use an empty separator
 - the suffix list can now include an empty suffix, so the caller must be 
taught not to pass an empty suffix to preserve previous usage pattern
   + _lt_decl_varnames_tagged was the only caller for now, so I optimized it as 
well
   + right now, lt_decl_varnames_tagged is never called with more than one 
argument.  It looks like it may have been intended to be called with multiple 
VARNAME arguments, rather than a single argument consisting of multiple 
VARNAMEs, but changing that is more invasive.  So for now I just added an 
assert which will trigger if we ever change our minds, to remind us to fix the 
usage patterns appropriately.

OK to apply?

$ echo 'm4_debugmode(qt)lt_combine([, ],[a,b],[_],[1],[2])' | m4 -Ilib -
Ilib/m4sugar m4sugar.m4 ltsugar.pre - 2>&1 |wc
    172     516    3788
$ echo 'm4_debugmode(qt)lt_combine([, ],[a,b],[_],[1],[2])' | m4 -Ilib -
Ilib/m4sugar m4sugar.m4 ltsugar.post - 2>&1 |wc
    101     303    2241
$ echo 'm4_divert(0)lt_combine([, ],[a,b],[_],[1],[2])' | m4 -Ilib -
Ilib/m4sugar m4sugar.m4 ltsugar.pre -
a_1,a_2,b_1,b_2
$ echo 'm4_divert(0)lt_combine([, ],[a,b],[_],[1],[2])' | m4 -Ilib -
Ilib/m4sugar m4sugar.m4 ltsugar.post -
a_1, a_2, b_1, b_2

2007-10-17  Eric Blake  <address@hidden>

        Speed up bootstrap by improving lt_combine.
        * libltdl/m4/ltsugar.m4 (lt_combine): Mirror Autoconf 2.62
        improvements.  Includes a semantic change where the separator can
        now be empty, and where an empty fourth argument is now treated as
        a valid suffix.
        * libltdl/m4/libtool.m4 (_lt_decl_varnames_tagged): Adjust to new
        semantics of lt_combine.
        (lt_decl_varnames_tagged): Fix quoting and optimize.


Index: libltdl/m4/libtool.m4
===================================================================
RCS file: /sources/libtool/libtool/libltdl/m4/libtool.m4,v
retrieving revision 1.120
diff -u -p -r1.120 libtool.m4
--- libltdl/m4/libtool.m4       12 Oct 2007 20:54:44 -0000      1.120
+++ libltdl/m4/libtool.m4       17 Oct 2007 17:29:37 -0000
@@ -367,12 +367,12 @@ m4_define([lt_decl_dquote_varnames],
 # lt_decl_varnames_tagged([SEPARATOR], [VARNAME1...])
 # ---------------------------------------------------
 m4_define([lt_decl_varnames_tagged],
-[_$0(m4_quote(m4_default([$1], [[, ]])),
-     m4_quote(m4_if([$2], [],
-                    m4_quote(lt_decl_tag_varnames),
-                 m4_quote(m4_shift($@)))),
-     m4_split(m4_normalize(m4_quote(_LT_TAGS))))])
-m4_define([_lt_decl_varnames_tagged], [lt_combine([$1], [$2], [_], $3)])
+[m4_assert([$# <= 2])dnl
+_$0(m4_quote(m4_default([$1], [[, ]])),
+    m4_ifval([$2], [[$2]], [m4_dquote(lt_decl_tag_varnames)]),
+    m4_split(m4_normalize(m4_quote(_LT_TAGS)), [ ]))])
+m4_define([_lt_decl_varnames_tagged],
+[m4_ifval([$3], [lt_combine([$1], [$2], [_], $3)])])
 
 
 # lt_decl_all_varnames([SEPARATOR], [VARNAME1...])
Index: libltdl/m4/ltsugar.m4
===================================================================
RCS file: /sources/libtool/libtool/libltdl/m4/ltsugar.m4,v
retrieving revision 1.7
diff -u -p -r1.7 ltsugar.m4
--- libltdl/m4/ltsugar.m4       16 Oct 2007 22:45:49 -0000      1.7
+++ libltdl/m4/ltsugar.m4       17 Oct 2007 17:29:37 -0000
@@ -7,7 +7,7 @@
 # unlimited permission to copy and/or distribute it, with or without
 # modifications, as long as this notice is preserved.
 
-# serial 5 ltsugar.m4
+# serial 6 ltsugar.m4
 
 # This is to help aclocal find these macros, as it can't see m4_define.
 AC_DEFUN([LTSUGAR_VERSION], [m4_if([0.1])])
@@ -63,14 +63,16 @@ m4_define([lt_append],
 # Produce a SEP delimited list of all paired combinations of elements of
 # PREFIX-LIST with SUFFIX1 through SUFFIXn.  Each element of the list
 # has the form PREFIXmINFIXSUFFIXn.
+# Needed until we can rely on m4_combine added in Autoconf 2.62.
 m4_define([lt_combine],
-[m4_if([$2], [], [],
-  [m4_if([$4], [], [],
-    [lt_join(m4_quote(m4_default([$1], [[, ]])),
-      lt_unquote(m4_split(m4_normalize(m4_foreach(_Lt_prefix, [$2],
-                  [m4_foreach(_Lt_suffix, lt_car([m4_shiftn(3, $@)]),
-                              [_Lt_prefix[]$3[]_Lt_suffix ])])))))])])dnl
-])
+[m4_if(m4_eval([$# > 3]), [1],
+       [m4_pushdef([_Lt_sep], [m4_define([_Lt_sep], [[$1]])])]]dnl
+[[m4_foreach([_Lt_prefix], [$2],
+            [m4_foreach([_Lt_suffix],
+               ]m4_dquote(m4_dquote(m4_shift(m4_shift(m4_shift($@)))))[,
+                        [_Lt_sep[]m4_defn(
+                                  [_Lt_prefix])[$3]m4_defn(
+                                                   [_Lt_suffix])])])])])
 
 
 # lt_if_append_uniq(MACRO-NAME, VARNAME, [SEPARATOR], [UNIQ], [NOT-UNIQ])






reply via email to

[Prev in Thread] Current Thread [Next in Thread]