Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Clean up and microoptimize str.translate and charmap codec #122561

Closed
@serhiy-storchaka

Description

@serhiy-storchaka

Initially I just planned to get rid of PyLong_AS_LONG (undocumented transitional alias of PyLong_AsLong) in Objects/unicodeobject.c. But I have used opportunity to add few optimizations in the nearby code. I do not expect significant performance boost, but some overhead was removed in specific corner cases:

  • PyLong_AsLongAndOverflow is now only called once for the replacement code (PyLong_AS_LONG was called twice).
  • Using PyMapping_GetOptionalItem instead of PyObject_GetItem allows to avoid raising a KeyError if the translation table is a dict. I left this case in previous round (Add PyMapping_GetOptionalItem() #106307) because this does not make the code simpler (we still need to handle other LookupError), but it still has a tiny performance benefit.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    performancePerformance or resource usage

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions