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

Alejandro Colomar via Mutt-dev <[email protected]>
Newsgroups gmane.mail.mutt.devel
Message-ID <aZbekPnatUdxEA67@devuan>
Hi Gero,

On 2026-02-19T03:48:43+0100, Gero Treuner wrote:
> On Thu, Feb 19, 2026 at 01:57:11AM +0100, Alejandro Colomar via Mutt-dev wrote:
> > > > 	char *
> > > > 	strchrnul(const char *s, int c)
> > > > 	{
> > > > 		char  *p;
> > > > 
> > > > 		p = strchr(s, c);
> > > > 		if (p == NULL)
> > > > 			return (char *) s + strlen(s);
> > > > 		return p;
> > > 
> > > This can be compacted into a one-liner:
> > > 
> > > 		return strchr(s, c) ?: (char *) s + strlen(s);
> > 
> > And avoiding the cast:
> > 
> > 	#define strnul(s)  strchr(s, '\0')
> > 
> > 	char *
> > 	strchrnul(const char *s, int c)
> > 	{
> > 		return strchr(s, c) ?: strnul(s);
> > 	}
> 
> On compiler level this replaces a function with 1 argument by
> another with 2 (although functionally equivalent).
> 
> Personally I don't have an issue with casts.

Casts are dangerous, and hurt readability.

> But I do care about the
> footprint on the end users system (even if the difference is small).

The optimization is so trivial that gcc -O1 produces the same assembly
for both:

	alx@devuan:~/tmp$ diff -u strchrnul*.c
	--- strchrnul1.c	2026-02-19 10:56:48.787467463 +0100
	+++ strchrnul2.c	2026-02-19 10:56:51.924802397 +0100
	@@ -1,6 +1,8 @@
	 #include <string.h>
	+#define strnul(s)  strchr(s, '\0')
	+
	 char *
	 strchrnul(const char *s, int c)
	 {
	-	return strchr(s, c) ?: (char *) s + strlen(s);
	+	return strchr(s, c) ?: strnul(s);
	 }
	alx@devuan:~/tmp$ gcc -S -O1 strchrnul*.c
	alx@devuan:~/tmp$ diff -u strchrnul*.s
	--- strchrnul1.s	2026-02-19 10:57:26.787769644 +0100
	+++ strchrnul2.s	2026-02-19 10:57:26.799769740 +0100
	@@ -1,4 +1,4 @@
	-	.file	"strchrnul1.c"
	+	.file	"strchrnul2.c"
		.text
		.globl	strchrnul
		.type	strchrnul, @function


Have a lovely day!
Alex

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

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmmW36AACgkQ64mZXMKQ
wqn6Fg//acN5wWt87ZqegLAAZy8MqIMWk/8WRUPa3r4Kw1ZOFQW2+pLOu3dWNkVF
6NDFtOU50epTxZUH79oFI2cLeLhkJ3wm29cBWza7atYcL48CZJaBrVqRvAuWGZWI
9W5Rz0Adw2hMbr6GoudGVF4ECejdRX40rSNwyBzeYmvp3//tuSYCKvdeSj22i2PK
6XX7qiukiSo36YwHWNX4Md5XueY3xGDdBzN696P5VhD+Is8vLQPy8jManF/zai1X
KMfdK0Q6A82b2qY7S+JznRBM2pBa0V3ELM1gT1j/aH33nWtbka0Y0Gnqpp/1WTAb
nun2wnlHaCZ2qDoHZyw8IZlZDsenrPXA+ADZVws6sVhl8lCkqDBjybjiXhmHYyhL
Cdm/7XccHc6l3tCoXYLoUcxnxy7aQ6IUCo6oengH0YWiWGYPOn/WJ6UTil6hxYBh
lsPGLSciVsKp0rSizbWVHiUHBXmAwu8yWWTt9Af3fPoYH/xpDrqvAResLKBDFO4y
3E5ftRQvnYB2f5zmC7ZE9M1+WWVucshQ8vP/3Qp1mbHdlfuNjkhw02scwZKLYUds
FAXLv852++Cm3vhOmDY37XYmfJ80MBpocm3d0v9F/HmrbAU+Yiu1rap6SCfi222S
YFNEs6wAmB/JNVoN3CIjciT46SWMqWGMvnZXJO/pEWemh8fqwYY=
=zVRN
-----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.