gh-129173: Use _PyUnicodeError_GetParams
in PyCodec_NameReplaceErrors
#129135
+123
−111
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I extracted the logic of rendering hexadecimal digits but this requires a double pointer (alternatively, I could make the function return the number of characters that were written and advance the pointer after the call).
If inlined calls are preferred, then we can convert the function into a macro to avoid duplications but I think a function call is not that slow (especially if I add the
inline
qualifier to force a bit the compiler to inline it and then allow it to possibly vectorize it if it's smart). Ideally, I would like to extract that logic fromPyCodec_XMLCharRefReplaceErrors
as well but it's the only place where we use the decimal base instead. OTOH, if we extract the logic, it's a bit cleaner to read.After the refactoring of surrogate handlers has been done, I will wrap up this list of PRs by cleaning up the handlers that I fixed previously (I just didn't want to do both cleanup and fixes in the same PR). The idea is to extract the handling of each unicode error type into a separate function (unless the handler only handles a single exception type as it's the case for the namereplace handler).
_PyUnicodeError_GetParams
#129173