[New-bugs-announce] [issue39588] Use memcpy() instead of for() loops in _PyUnicode_To*

Andy Lester report at bugs.python.org
Sat Feb 8 16:45:29 EST 2020

New submission from Andy Lester <andy at petdance.com>:

Four functions in Objects/unicodectype.c copy values out of lookup tables with a for loop

        int i;
        for (i = 0; i < n; i++)
            res[i] = _PyUnicode_ExtendedCase[index + i];

instead of a memcpy

        memcpy(res, &_PyUnicode_ExtendedCase[index], n * sizeof(Py_UCS4));

My Apple clang version 11.0.0 on my Mac optimizes away the for loop and generates equivalent code to the memcpy.

gcc 4.8.5 on my Linux box (the newest GCC I have) does not optimize away the loop.

The four functions are:

components: Unicode
messages: 361636
nosy: ezio.melotti, petdance, vstinner
priority: normal
severity: normal
status: open
title: Use memcpy() instead of for() loops in _PyUnicode_To*
type: performance

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list