On Mon, Nov 23, 2015 at 11:42 PM, Yann Ylavic <[email protected]> wrote:
> except -Os I always have better
> results with the "optimized" version

To reach better performances with -Os, we could possibly use:

int ap_strcasecmp(const char *s1, const char *s2)
{
    const unsigned char *ps1 = (const unsigned char *) s1;
    const unsigned char *ps2 = (const unsigned char *) s2;
    for (;;) {
        const unsigned int c1 = ucharmap[*ps1++],
                           c2 = ucharmap[*ps2++];
        if (c1 != c2) {
            return c1 - c2;
        }
        if (c1 == '\0') {
            break;
        }
    }
    return (0);
}

int ap_strncasecmp(const char *s1, const char *s2, int n)
{
    const unsigned char *ps1 = (const unsigned char *) s1;
    const unsigned char *ps2 = (const unsigned char *) s2;
    while (n--) {
        const unsigned int c1 = ucharmap[*ps1++],
                           c2 = ucharmap[*ps2++];
        if (c1 != c2) {
            return c1 - c2;
        }
        if (c1 == '\0') {
            break;
        }
    }
    return (0);
}

This implementation with -Os is ~13% slower than str[n]casemp(),
whereas the original ap_str[n]casemp() is ~30% slower.

Don't know if it happens/makes sense to compile httpd with -Os...
At least for APR, I think we could take that into consideration.

Reply via email to