Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
mpage committed Dec 6, 2024
1 parent 13a05a0 commit eb8ce39
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions Python/specialize.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ specialize_dict_access(
}
write_u32(cache->version, type->tp_version_tag);
cache->index = (uint16_t)offset;
instr->op.code = values_op;
specialize(instr, values_op);
}
else {
PyDictObject *dict = _PyObject_GetManagedDict(owner);
Expand All @@ -999,7 +999,7 @@ specialize_dict_access(
}
cache->index = (uint16_t)index;
write_u32(cache->version, type->tp_version_tag);
instr->op.code = hint_op;
specialize(instr, hint_op);
}
return 1;
}
Expand Down Expand Up @@ -1101,7 +1101,7 @@ specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* na
write_u32(lm_cache->type_version, type->tp_version_tag);
/* borrowed */
write_obj(lm_cache->descr, fget);
instr->op.code = LOAD_ATTR_PROPERTY;
specialize(instr, LOAD_ATTR_PROPERTY);
return 0;
}
case OBJECT_SLOT:
Expand All @@ -1125,7 +1125,7 @@ specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* na
assert(offset > 0);
cache->index = (uint16_t)offset;
write_u32(cache->version, type->tp_version_tag);
instr->op.code = LOAD_ATTR_SLOT;
specialize(instr, LOAD_ATTR_SLOT);
return 0;
}
case DUNDER_CLASS:
Expand All @@ -1134,7 +1134,7 @@ specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* na
assert(offset == (uint16_t)offset);
cache->index = (uint16_t)offset;
write_u32(cache->version, type->tp_version_tag);
instr->op.code = LOAD_ATTR_SLOT;
specialize(instr, LOAD_ATTR_SLOT);
return 0;
}
case OTHER_SLOT:
Expand Down Expand Up @@ -1170,7 +1170,7 @@ specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* na
/* borrowed */
write_obj(lm_cache->descr, descr);
write_u32(lm_cache->type_version, type->tp_version_tag);
instr->op.code = LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN;
specialize(instr, LOAD_ATTR_GETATTRIBUTE_OVERRIDDEN);
return 0;
}
case BUILTIN_CLASSMETHOD:
Expand All @@ -1194,6 +1194,7 @@ specialize_instance_load_attr(PyObject* owner, _Py_CODEUNIT* instr, PyObject* na
if (shadow) {
goto try_instance;
}
set_counter((_Py_BackoffCounter*)instr + 1, adaptive_counter_cooldown());
return 0;
}
Py_UNREACHABLE();
Expand Down Expand Up @@ -1433,10 +1434,10 @@ specialize_class_load_attr(PyObject *owner, _Py_CODEUNIT *instr,
write_obj(cache->descr, descr);
if (metaclass_check) {
write_u32(cache->keys_version, Py_TYPE(cls)->tp_version_tag);
instr->op.code = LOAD_ATTR_CLASS_WITH_METACLASS_CHECK;
specialize(instr, LOAD_ATTR_CLASS_WITH_METACLASS_CHECK);
}
else {
instr->op.code = LOAD_ATTR_CLASS;
specialize(instr, LOAD_ATTR_CLASS);
}
return 0;
#ifdef Py_STATS
Expand Down Expand Up @@ -1472,7 +1473,7 @@ PyObject *descr, DescriptorClassification kind, bool is_method)
return 0;
}
write_u32(cache->keys_version, keys_version);
instr->op.code = is_method ? LOAD_ATTR_METHOD_WITH_VALUES : LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES;
specialize(instr, is_method ? LOAD_ATTR_METHOD_WITH_VALUES : LOAD_ATTR_NONDESCRIPTOR_WITH_VALUES);
}
else {
Py_ssize_t dictoffset;
Expand All @@ -1487,7 +1488,7 @@ PyObject *descr, DescriptorClassification kind, bool is_method)
}
}
if (dictoffset == 0) {
instr->op.code = is_method ? LOAD_ATTR_METHOD_NO_DICT : LOAD_ATTR_NONDESCRIPTOR_NO_DICT;
specialize(instr, is_method ? LOAD_ATTR_METHOD_NO_DICT : LOAD_ATTR_NONDESCRIPTOR_NO_DICT);
}
else if (is_method) {
PyObject *dict = *(PyObject **) ((char *)owner + dictoffset);
Expand All @@ -1501,7 +1502,7 @@ PyObject *descr, DescriptorClassification kind, bool is_method)
dictoffset -= MANAGED_DICT_OFFSET;
assert(((uint16_t)dictoffset) == dictoffset);
cache->dict_offset = (uint16_t)dictoffset;
instr->op.code = LOAD_ATTR_METHOD_LAZY_DICT;
specialize(instr, LOAD_ATTR_METHOD_LAZY_DICT);
}
else {
SPECIALIZATION_FAIL(LOAD_ATTR, SPEC_FAIL_ATTR_CLASS_ATTR_SIMPLE);
Expand Down

0 comments on commit eb8ce39

Please sign in to comment.