-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-122561: Clean up and microoptimize str.translate and charmap codec #122932
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
gh-122561: Clean up and microoptimize str.translate and charmap codec #122932
Conversation
… codec * Replace PyLong_AS_LONG() with PyLong_AsLong(). * Call PyLong_AsLong() only once per the replacement code. * Use PyMapping_GetOptionalItem() instead of PyObject_GetItem().
@@ -8935,15 +8946,20 @@ unicode_translate_call_errorhandler(const char *errors, | |||
which must be decrefed by the caller. | |||
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) |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -8594,7 +8606,7 @@ charmapencode_output(Py_UCS4 c, PyObject *mapping, | |||
return enc_SUCCESS; | |||
} | |||
|
|||
rep = charmapencode_lookup(c, mapping); | |||
rep = charmapencode_lookup(c, mapping, &replace); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
Uh oh!
There was an error while loading. Please reload this page.