Skip to content

Commit 6fb6e4a

Browse files
committed
Small optimization for STORE_ATTR specialize.
If the type is new and a version tag hasn't yet been assigned, we would fail to specialize it. Use `_PyType_LookupRefAndVersion()` instead of `type_get_version()`, which will assign a version.
1 parent 62c8197 commit 6fb6e4a

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Python/specialize.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -944,13 +944,13 @@ analyze_descriptor_load(PyTypeObject *type, PyObject *name, PyObject **descr) {
944944
#endif //!Py_GIL_DISABLED
945945

946946
static DescriptorClassification
947-
analyze_descriptor_store(PyTypeObject *type, PyObject *name, PyObject **descr)
947+
analyze_descriptor_store(PyTypeObject *type, PyObject *name, PyObject **descr, unsigned int *tp_version)
948948
{
949949
if (type->tp_setattro != PyObject_GenericSetAttr) {
950950
*descr = NULL;
951951
return GETSET_OVERRIDDEN;
952952
}
953-
PyObject *descriptor = _PyType_LookupRef(type, name);
953+
PyObject *descriptor = _PyType_LookupRefAndVersion(type, name, tp_version);
954954
*descr = descriptor;
955955
if (descriptor_is_class(descriptor, name)) {
956956
return DUNDER_CLASS;
@@ -1330,11 +1330,11 @@ _Py_Specialize_StoreAttr(_PyStackRef owner_st, _Py_CODEUNIT *instr, PyObject *na
13301330
SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_OVERRIDDEN);
13311331
goto fail;
13321332
}
1333-
uint32_t tp_version = type_get_version(type, STORE_ATTR);
1333+
unsigned int tp_version = 0;
1334+
DescriptorClassification kind = analyze_descriptor_store(type, name, &descr, &tp_version);
13341335
if (tp_version == 0) {
13351336
goto fail;
13361337
}
1337-
DescriptorClassification kind = analyze_descriptor_store(type, name, &descr);
13381338
assert(descr != NULL || kind == ABSENT || kind == GETSET_OVERRIDDEN);
13391339
switch(kind) {
13401340
case OVERRIDING:

0 commit comments

Comments
 (0)