Re: m4sugar and m4 1.6, bison

Ralf Wildenhues <[email protected]>
Newsgroups gmane.comp.sysutils.autoconf.patches,gmane.comp.gnu.m4.general
Organization Department of Numerical Simulation, University of Bonn
Message-ID <[email protected]>
* Ralf Wildenhues wrote on Sat, Jul 12, 2008 at 08:11:55AM CEST:
> So then here's a first prototype for fast m4_append_uniq, completely
> untested, and would probably need some more-unique separator after $1 in
> the definition of m4_key.

I'll blame it on lack of coffee...

> # m4_make_macro_name(STRING)
> # Turn all characters not fitting to be a macro name into '_'.
> m4_define([m4_make_macro_name],
> [m4_bpatsubst([$1], [...])dnl
> ])
> 
> # m4_append_uniq(MACRO-NAME, STRING, [SEPARATOR], [IF-UNIQ], [IF-DUP])
> m4_define([m4_append_uniq],
> [m4_pushdef([m4_key], [_$1_[]make_macro_name([$2])])dnl
> m4_ifdef(m4_key,
>   [m4_if([m4_defn(m4_key)], [$2],

This is completely ignoring hash key collision.  So, assuming that
collisions are rare, i.e., usually strings differ not only in characters
not allowed in a macro name, then the duplicate test here can just reuse
the one from the version of m4_append_uniq currently in Autoconf.  That
will probably still give amortized fast check here.  Actually, I guess
the uniq part is even O(n), only the reallocs necessary now and then
will be loglinear.

>     [$5],
>     [_$1($@)])],
>   [_$1($@)])dnl
> m4_popdef([m4_key])dnl
> ])
> 
> m4_define([_m4_append_uniq],
> [m4_define(m4_key, m4_defn(m4_key))dnl

Then this line can simply be:
[m4_define(m4_key)dnl

> do the appending work, expand $4...
> ])

Still completely untested, of course...

Cheers,
Ralf
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.