-
Notifications
You must be signed in to change notification settings - Fork 48
Open
python/mypy
#20948Description
Add primitives for s.lower() and s.upper() on str objects. There aren't any Python C API functions that directly implement these, so we'll need to add full implementations. Here are some ideas:
- Use
Py_UNICODE_TOLOWERandPy_UNICODE_TOUPPERto convert individual characters to upper/lower case.- Use a static table for the lower 128 or 256 character codes to avoid per-character function calls in common cases. Or maybe we can use some tricks to avoid table lookups on ascii characters? A table lookup is probably better than a branch that can't be predicted, though.
- Create an uninitialized new str object and set the contents directly per-character.
- We may need to set the string kind (1/2/4 bytes per character) directly for optimal performance.
- Some code points are special, at least sigma. Look at the CPython implementation and tests to ensure we match the semantics 100%.
- One option is to copy paste from CPython, if they don't rely on (too many) static functions that we'd need to vendor as well.
Reactions are currently unavailable