Hi Bruno, On 2026-02-24T15:49:38+0100, Bruno Haible wrote: > Alejandro Colomar wrote: > > This finds the first non-'/'. Since the first character is a '/' (we > > have set that a few lines above in `*slash = '/';`), we were manually > > skipping it. > > That's the perfect way to write such a thing. > > > However, that's unnecessary, since the function will > > similarly skip it. > > > > It seems a benign off-by-one mental bug, which didn't result in any > > actual bug, but still worth "fixing", or rather, simplifying. > > No, that's not a simplification, but adding a computation that we already > know is unnecessary (and that the compiler typically will not optimize away). > > De-optimization is OK when it improves maintainability. But here, it doesn't > do so. As a programmer, one only needs to look 3 lines above to see why the > code is correct.
Hmmm, the de-optimization removes a hardcoded single operation, and introduces one iteration of strspn(3), which is relatively cheap (maybe a low single-digit number of operations), but certainly not one operation. This looks like a de-optimization, but I'm pretty sure it can't be measured meaningfully. Also, the reduction in code size might have also an optimizing effect in some cases. So, either way is good, I guess. The transformation from find_non_slash() to stpspn() is going to chop more operations than this de-optimization would be adding, BTW. Cheers, Alex -- <https://www.alejandro-colomar.es>
signature.asc
Description: PGP signature
