-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-129173: Use _PyUnicodeError_GetParams
in PyCodec_NameReplaceErrors
#129135
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
Conversation
_PyUnicodeError_GetParams
for the 'namereplace' handler_PyUnicodeError_GetParams
for the 'namereplace' handler
_PyUnicodeError_GetParams
for the 'namereplace' handler_PyUnicodeError_GetParams
in PyCodec_NameReplaceErrors
Since I will be leaving for two weeks and won't be able to commit or review anything (except on mobile), I kept it as a draft and we'll discuss about it later. What remains do to on the codecs part is mainly refactoring so it's just a feature. |
Co-authored-by: Petr Viktorin <[email protected]>
static inline functions are definitely preferred to macros :) |
In this case, it's just that I need to pass a double pointer, which made it a bit more ugly, but I think it's better like that rather than keeping everything in the loop (it's much more harder to actually see what's happening and I doubt this will really slow down the handler by much). |
Well, I wouldn't want to see |
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
and extract complex logic into separate functions #129173