bug-gnulib
[Top][All Lists]
Advanced

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

Re: [PATCH] mbrtowc: remove a redundant condition


From: Benno Schulenberg
Subject: Re: [PATCH] mbrtowc: remove a redundant condition
Date: Mon, 22 Mar 2021 11:29:54 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.10.0

Op 21-03-2021 om 19:22 schreef Bruno Haible:
> Hi Benno,
> 
>> * lib/mbrtowc-impl-utf8.h: There is no need to check for c == 0xf4
>> when !(c < 0xf4), as ten lines earlier c <= 0xf4 was established.
> 
> Your patch is correct. But we generally don't need to do micro-
> optimizations that a compiler easily can do for us.

Yeah, I guess that the compiler could elide this superfluous condition.
But does it actually do it?  How many steps back does it take?

> Just curious:
> Did you get a compiler warning about this code? If so, from which
> compiler? Or did you find this redundancy by staring at the code?

By staring at the code and trying to understand whether I am missing
something, why that c == 0xf4 is there.

I was looking at the code to see how conversion from multibyte to
wide character is done, whether it's worth it to give nano its own
copy.  There is quite some overhead at the beginning, and nano doesn't
need to do the checks on m.  Also, I want nano's version to return -1
for codes beyond U+10FFFF.  The mbtowc from glibc returns 4 for codes
from U+110000 to U+1FFFFF, but those are not valid UTF-8 sequences,
so nano would need to do another check afterward.

Benno

Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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