-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
bpo-39156: Break up COMPARE_OP into four logically distinct opcodes. #17754
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
3f4e3d4
to
2ee4c16
Compare
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 have some minor comments.
Doc/library/dis.rst
Outdated
@@ -961,6 +975,13 @@ All of the following opcodes use their arguments. | |||
|
|||
.. versionadded:: 3.1 | |||
|
|||
.. opcode:: JUMP_IF_NOT_EXC_MATCH (target) | |||
|
|||
Tests whether the second value on the stack is an exception matching TOS, and jumps if it is not. |
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.
This should be wrapped at 80 chars.
Python/ceval.c
Outdated
PyObject *left = POP(); | ||
if (PyTuple_Check(right)) { | ||
Py_ssize_t i, length; | ||
length = PyTuple_Size(right); |
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 think PyTuple_GET_SIZE()
should be used here.
Python/ceval.c
Outdated
if (PyTuple_Check(right)) { | ||
Py_ssize_t i, length; | ||
length = PyTuple_Size(right); | ||
for (i = 0; i < length; i += 1) { |
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++
int res = PyErr_GivenExceptionMatches(left, right); | ||
Py_DECREF(left); | ||
Py_DECREF(right); | ||
if (res > 0) { |
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.
IMO, this check for res > 0
should not be included.
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.
Why?
COMPARE_OP for rich comparisons IS_OP for 'is' and 'is not' tests CONTAINS_OP for 'in' and 'is not' tests JUMP_IF_NOT_EXC_MATCH for checking exceptions in 'try-except' statements.
3e24674
to
8dbef33
Compare
8dbef33
to
1486559
Compare
8f56c51
to
449cb17
Compare
449cb17
to
5c9a327
Compare
…ythonGH-17754) Break up COMPARE_OP into four logically distinct opcodes: * COMPARE_OP for rich comparisons * IS_OP for 'is' and 'is not' tests * CONTAINS_OP for 'in' and 'is not' tests * JUMP_IF_NOT_EXC_MATCH for checking exceptions in 'try-except' statements.
Breaks up COMPARE_OP into four logically distinct opcodes:
This improves the clarity of the interpreter and should provide a modest speedup.
https://bugs.python.org/issue39156