autoconf-patches
[Top][All Lists]
Advanced

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

m4_strpbrk? [was: Faster AC_CHECK_{HEADERS,FUNCS}]


From: Eric Blake
Subject: m4_strpbrk? [was: Faster AC_CHECK_{HEADERS,FUNCS}]
Date: Fri, 14 Nov 2008 08:23:47 -0700
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.17) Gecko/20080914 Thunderbird/2.0.0.17 Mnenhy/0.7.5.666

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Paolo Bonzini on 11/14/2008 12:59 AM:
>> +[m4_pushdef([AC_func], m4_if(m4_index(m4_translit([$1], [   ][
>> +$`], [    ]), [ ]), [-1], [[$1]], [[$ac_func]]))]dnl
> 
> Also, could you factor the
> m4_index(m4_translit(...)) to a m4_strbrk macro?

Not as efficiently.  The case above exploited: 1. the fact that space was
one of the characters searched for (it converts tab, newline, $, and `
into space, then searches for any of 5 characters), and 2. the fact that
the character set size is fixed.  An almost-generic strpbrk is possible
(you can't very easily handle [ or ] in the set of characters, and - must
not occur in the middle), using this (untested), but notice the extra
overhead of m4_format, m4_len, and a second m4_translit.

# m4_strpbrk(STRING, BYTES)
# -------------------------
# Return the index within STRING of the first occurrence of any
# byte in BYTES, or -1 if there are none.  Behavior is unspecified
# if BYTES includes [, ], or -.
m4_define([m4_strpbrk],
[m4_index(m4_translit([[$1]], [$2],
    m4_translit(m4_format([%.*s], m4_len([$2]), []), [ ], [$2])),
  m4_format([[%.1s]], [$2]))])

I'd have to benchmark it to see if this much overhead starts to tip the
balance in favor of m4_bregexp (which also introduces problems searching
for an ill-placed ^).
m4_define([m4_strpbrk],
[m4_bregexp([$1], [[$2]])])

- --
Don't work too hard, make some time for fun as well!

Eric Blake             address@hidden
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iEYEARECAAYFAkkdmAMACgkQ84KuGfSFAYDO0QCfUf6htQ6tKYH+5krTHw5CtIW4
JVUAoL2bILShVWKZ9M1a44nxbml8D/f2
=TYbm
-----END PGP SIGNATURE-----




reply via email to

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