Skip to content

Commit ce0cd38

Browse files
committed
Simplify even more
1 parent 3d0df4c commit ce0cd38

File tree

2 files changed

+18
-23
lines changed

2 files changed

+18
-23
lines changed

Python/optimizer_bytecodes.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -894,21 +894,18 @@ dummy_func(void) {
894894
// the result is always a bool, but sometimes we can
895895
// narrow it down to True or False
896896
res = sym_new_type(ctx, &PyBool_Type);
897+
PyTypeObject *inst_type = sym_get_type(instance);
897898
PyTypeObject *cls_o = (PyTypeObject *)sym_get_const(ctx, cls);
898-
if (cls_o && sym_matches_type(cls, &PyType_Type)) {
899-
// isinstance(obj, cls) where cls is a known class
900-
PyTypeObject *inst_type = sym_get_type(instance);
901-
if (inst_type) {
902-
// isinstance(obj, cls) where both obj and cls have
903-
// known types meaning we can deduce either True or False
904-
905-
// The below check is equivalent to PyObject_TypeCheck(inst, cls)
906-
if (sym_matches_type(instance, cls_o) || PyType_IsSubtype(inst_type, cls_o)) {
907-
sym_set_const(res, Py_True);
908-
}
909-
else {
910-
sym_set_const(res, Py_False);
911-
}
899+
if (inst_type && cls_o && sym_matches_type(cls, &PyType_Type)) {
900+
// isinstance(inst, cls) where both inst and cls have
901+
// known types, meaning we can deduce either True or False
902+
903+
// The below check is equivalent to PyObject_TypeCheck(inst, cls)
904+
if (sym_matches_type(instance, cls_o) || PyType_IsSubtype(inst_type, cls_o)) {
905+
sym_set_const(res, Py_True);
906+
}
907+
else {
908+
sym_set_const(res, Py_False);
912909
}
913910
}
914911
}

Python/optimizer_cases.c.h

Lines changed: 7 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)