{{ message }}
gh-106307: Add PyMapping_GetOptionalItem()#106308
Merged
serhiy-storchaka merged 10 commits intoJul 11, 2023
Merged
Conversation
Replacement of PyObject_GetItem() which doesn't raise KeyError. int _PyMapping_LookupItem(PyObject *obj, PyObject *key, PyObject **result) Return 1 and set *result != NULL if a key is found. Return 0 and set *result == NULL if a key is not found; a KeyError is silenced. Return -1 and set *result == NULL if an error other than KeyError is raised.
cfc5851 to
078ea48
Compare
July 1, 2023 20:46
vstinner
reviewed
Jul 2, 2023
carljm
reviewed
Jul 7, 2023
carljm
left a comment
Member
There was a problem hiding this comment.
The bytecodes.c cleanups alone (i.e. the existing cases where we cared enough about perf to special-case the exact-dict fast path) clearly show the value of this API! Now all call sites can get the same perf benefit, with much less verbosity.
Sorry, something went wrong.
vstinner
reviewed
Jul 7, 2023
Co-authored-by: Carl Meyer <carl@oddbird.net> Co-authored-by: Victor Stinner <vstinner@python.org>
Co-authored-by: Carl Meyer <carl@oddbird.net>
vstinner
approved these changes
Jul 8, 2023
vstinner
left a comment
Member
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
encukou
reviewed
Jul 10, 2023
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.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.
Replacement of PyObject_GetItem() which doesn't raise KeyError.
Return 1 and set *result != NULL if a key is found.
Return 0 and set *result == NULL if a key is not found; a KeyError is silenced.
Return -1 and set *result == NULL if an error other than KeyError is raised.