Hi Bruno,

On Fri, Sep 26, 2025 at 09:54:20AM +0200, Alejandro Colomar wrote:
> >   I think that the cases where the programmer wants a pointer (not just
> >   a bool value) is 10% of the use-cases or less.
> 
> That guess is far from my numbers.
> 
> Here are the actual numbers in shadow utils.  The first column is the
> case-sensitive version, and the second column the case-insensitive one.
> 
>               str*    strcase*        TOTAL
> 
> prefix bool:  56      3               59
> prefix ptr:   13      0               13
> 
> suffix bool:  2       0               2
> suffix ptr:   0       1               1
> 
> 
>       $ echo 'scale=4; 13 / (59 + 13)' | bc
>       .1805
>       $ echo 'scale=4; 1 / (2 + 1)' | bc
>       .3333
> 
> It's around 20% for the prefix, and around 30% for the suffix.

Today, I found I could replace some uses of strprefix() by calls to the
standard strspn(3) and strcspn(3).  The patch does things like this:

        -       if (strprefix(s, "+") || strprefix(s, "-"))
        +       if (strspn(s, "+-"))
                continue;

I've also replaced one strsuffix() by strrspn(), which is not standard,
but makes the code simpler (and it made it more robust too).

<https://github.com/shadow-maint/shadow/pull/1369>
<https://github.com/shadow-maint/shadow/pull/1370>

I've got rid of a significant amount of strprefix() calls, and after
those patches, the numbers are:

                str*    strcase*        TOTAL

prefix bool:    37      3               40
prefix ptr:     13      0               13

suffix bool:    1       0               1
suffix ptr:     0       1               1

        $ echo 'scale=4; 13 / (40 + 13)' | bc
        .2452
        $ echo 'scale=4; 1 / (1 + 1)' | bc
        .5000

Around 25% for the prefix, and 50% for the suffix, return a pointer.


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

Attachment: signature.asc
Description: PGP signature

Reply via email to