KEMBAR78
Add specialization for strings in builtin_len · Issue #835 · mypyc/mypyc · GitHub
Skip to content

Add specialization for strings in builtin_len #835

@97littleleaf11

Description

@97littleleaf11

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions