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

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serhiy-storchaka opened this issue Aug 1, 2024 · 2 comments
Closed

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

serhiy-storchaka opened this issue Aug 1, 2024 · 2 comments
Labels
performance Performance or resource usage

Comments

@serhiy-storchaka
Copy link
Member

serhiy-storchaka commented Aug 1, 2024

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

@mdboom mdboom added the performance Performance or resource usage label Aug 1, 2024
@vstinner
Copy link
Member

vstinner commented Aug 9, 2024

Do you plan to create a pull request?

@serhiy-storchaka
Copy link
Member Author

I thought that I already created a PR. Now I have to find where it went.

serhiy-storchaka added a commit to serhiy-storchaka/cpython that referenced this issue Aug 12, 2024
… codec

* Replace PyLong_AS_LONG() with PyLong_AsLong().
* Call PyLong_AsLong() only once per the replacement code.
* Use PyMapping_GetOptionalItem() instead of PyObject_GetItem().
serhiy-storchaka added a commit that referenced this issue Aug 28, 2024
…GH-122932)

* Replace PyLong_AS_LONG() with PyLong_AsLong().
* Call PyLong_AsLong() only once per the replacement code.
* Use PyMapping_GetOptionalItem() instead of PyObject_GetItem().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
performance Performance or resource usage
Projects
None yet
Development

No branches or pull requests

3 participants