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

Skip to content

gh-122561: Clean up and microoptimize str.translate and charmap codec#122932

Merged
serhiy-storchaka merged 3 commits intopython:mainfrom
serhiy-storchaka:unicode-translate
Aug 28, 2024
Merged

gh-122561: Clean up and microoptimize str.translate and charmap codec#122932
serhiy-storchaka merged 3 commits intopython:mainfrom
serhiy-storchaka:unicode-translate

Conversation

@serhiy-storchaka
Copy link
Copy Markdown
Member

@serhiy-storchaka serhiy-storchaka commented Aug 12, 2024

  • Replace PyLong_AS_LONG() with PyLong_AsLong().
  • Call PyLong_AsLong() only once per the replacement code.
  • Use PyMapping_GetOptionalItem() instead of PyObject_GetItem().

… codec

* Replace PyLong_AS_LONG() with PyLong_AsLong().
* Call PyLong_AsLong() only once per the replacement code.
* Use PyMapping_GetOptionalItem() instead of PyObject_GetItem().
Comment thread Objects/unicodeobject.c
Comment thread Objects/unicodeobject.c
Return 0 on success, -1 on error */
static int
charmaptranslate_lookup(Py_UCS4 c, PyObject *mapping, PyObject **result)
charmaptranslate_lookup(Py_UCS4 c, PyObject *mapping, PyObject **result, Py_UCS4 *replace)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain in the comment when replace is set?

Copy link
Copy Markdown
Member

@vstinner vstinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread Objects/unicodeobject.c
}

rep = charmapencode_lookup(c, mapping);
rep = charmapencode_lookup(c, mapping, &replace);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can move unsigned char replace; declaration here, to reduce the scope of the variable.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added it next to the declaration of rep, as in all other cases.

@serhiy-storchaka serhiy-storchaka merged commit 1a0b828 into python:main Aug 28, 2024
@serhiy-storchaka serhiy-storchaka deleted the unicode-translate branch August 28, 2024 09:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants