Re: [PATCH] wip: change ISSPACE to use ascii whitespace check.

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZeOM3sbAm6t-mq6@devuan>
On 2026-02-19T23:18:16+0100, Steffen Nurpmeso wrote:
> Hello Alejandro!

Hello Steffen!

> 
> Alejandro Colomar wrote in
>  <aZeGabzZUpS4fT4B@devuan>:
>  |On 2026-02-19T22:15:29+0100, Steffen Nurpmeso wrote:
>  |> Crystal Kolipe via Mutt-dev wrote in
>  |>  <[email protected]>:
>  |>|On Thu, Feb 19, 2026 at 02:32:45PM +0100, Alejandro Colomar via Mutt-dev \
>  |>|\
>  |>|wrote:
>  |> 
>  |> I think "the best" is a table lookup.
>  |> I use the below script to create a lookup table, it is easily
>  |> adaptable (it is 128 bytes + alignment, and it could be like this
>  |> ASM looks even better, all in all.
>  |
>  |By "best" are you optimizing for performance or readability?  I prefer
>  |readability any day.  We're not libc nor cc(1); we don't need to
>  |have the absolute best performance, or we'd be writing assembly (this is
>  |what glibc does, indeed).  We can get 80% of the juice with trivial
>  |one-liners that get optimized by the compiler and libc.
> 
> You were talking assembly!  But i am too, yes, i mean x86 has
> an explicit XLAT instruction, for example (never used it).
> In general with a constant single-instance lookup table and
> all-inlined accessors of that, .. of course the table is to be
> located relatively to the global offset table, but no "call" at
> all, could turn out as maybe even two instructions ("test(b) bit,
> mem", plus whatever then comes).
> If you make the table 256 bytes you can even scratch "is-7-bit"
> check and simply do table[(u8)..char..] & BIT1[|BIT2..].
> (Ie, that is the other nice thing, you could test certain things
> with one lookup, ie space|punct|alnum, or whatever.)

That's indeed what I'd expect of a good libc implementation.  But
I don't want to do that.  Readability is much more important to me.
I was checking the assembly to show that even though the code looked
quite heavy at first glance, it wasn't that much (compared to other
implementations that use more basic string functions).

Of course, a LUT beats anything, but the implementation is far from
readable.  And it only works for isascii(3) functions, but not so much
for skipws(), because you need to write a loop, at which point you don't
necessarily beat strspn(s,CTYPE_SPACE_C) anymore.  So isascii(3) APIs
are only so fast in theory; most often, the fastest approach is to not
use isascii(3) at all, but use strspn(s," \t") or something similar.


Cheers,
Alex

> 
> --steffen
> |
> |Der Kragenbaer,                The moon bear,
> |der holt sich munter           he cheerfully and one by one
> |einen nach dem anderen runter  wa.ks himself off
> |(By Robert Gernhardt)

-- 
<https://www.alejandro-colomar.es>
signature.asc (application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmXj0kACgkQ64mZXMKQ
wqlRXxAAvcPlUW+08SwNl8GaB7ExTbwZq//ZMSoqF3WvEsihGaD1gAgAPt296mua
beZj2TPkk4iYVLqmCMUoQU/m3TyKEZ4D5rwr6t5rsxxcP+iNlbNrxcS17a2/0Etp
kuy5RLe20FXVMtXAd2lhel5u7kTEyMdp8UhMJIdlK+8FnpJ0st9Ly0z0ll1ysBSf
b2u0/VPL/Ong1/zFf0pmm3dis4mBJWyDSk+OUodhMN0ZnJ3I8kDKmI2qTNVciSW9
NKEQoy3v6iCDm3FX45ZQx3VOqO/QX/INnXqiGe3hUYG4BCsQ2hhI0acCY4TjDg0B
2vTxrsVbZxDEw5Zldannm4eOIjRJqqUGOPTRqQERYtLjBEEN7Wgrw6Nxe2k10ZCk
SGTJeldqYEFXKALAlp0cPh+ghuTnb6gJWbpVTJ2m06J5StTgZOS25Hd35mXU8zQU
8e94e2mb8sO0uWGXfYwJKKjUYvI0qTa9REIu4OyA+eA0JnQ4GWZIGIiSagUOgsWA
iU4ZPbyxwO7Sj4UejGQcywLfuyXy07ggZE0Gv6SLpwilBSb6PuwVLtgFPZ8F9twz
RQwCTgrg+f9E/1IUrPbGa7sWelr8mHzPs4Rz5Zpcr/oH4ge71nZuCIFWBk6NoUgz
NOnkYx7yrPrtPvb41BFvv1TznSgIy4Mm+b9gPgyxlhElhi849wM=
=SMLm
-----END PGP SIGNATURE-----
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.