There is no special shortcut for str_rprimitive in builtin_len currently.
We may:
- Add a branch for
str_rpimitive
- Reduce redundant codes
We may directly get length from PyUnicodeObject using LoadMem method.
#define PyUnicode_GET_LENGTH(op) \
(assert(PyUnicode_Check(op)), \
assert(PyUnicode_IS_READY(op)), \
((PyASCIIObject *)(op))->length)
#define PyUnicode_IS_READY(op) (((PyASCIIObject*)op)->state.ready)
According to CPython's comments, the length member would be 0 when PyUnicode is not ready. Maybe it's ok to omit the IS_READY check?