Skip to content

Commit 047dc87

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 0497163 commit 047dc87

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
@@ -932,13 +932,13 @@ analyze_descriptor_load(PyTypeObject *type, PyObject *name, PyObject **descr) {
932932
}
933933

934934
static DescriptorClassification
935-
analyze_descriptor_store(PyTypeObject *type, PyObject *name, PyObject **descr)
935+
analyze_descriptor_store(PyTypeObject *type, PyObject *name, PyObject **descr, unsigned int *tp_version)
936936
{
937937
if (type->tp_setattro != PyObject_GenericSetAttr) {
938938
*descr = NULL;
939939
return GETSET_OVERRIDDEN;
940940
}
941-
PyObject *descriptor = _PyType_LookupRef(type, name);
941+
PyObject *descriptor = _PyType_LookupRefAndVersion(type, name, tp_version);
942942
*descr = descriptor;
943943
if (descriptor_is_class(descriptor, name)) {
944944
return DUNDER_CLASS;
@@ -1314,11 +1314,11 @@ _Py_Specialize_StoreAttr(_PyStackRef owner_st, _Py_CODEUNIT *instr, PyObject *na
13141314
SPECIALIZATION_FAIL(STORE_ATTR, SPEC_FAIL_OVERRIDDEN);
13151315
goto fail;
13161316
}
1317-
uint32_t tp_version = type_get_version(type, STORE_ATTR);
1317+
unsigned int tp_version = 0;
1318+
DescriptorClassification kind = analyze_descriptor_store(type, name, &descr, &tp_version);
13181319
if (tp_version == 0) {
13191320
goto fail;
13201321
}
1321-
DescriptorClassification kind = analyze_descriptor_store(type, name, &descr);
13221322
assert(descr != NULL || kind == ABSENT || kind == GETSET_OVERRIDDEN);
13231323
switch(kind) {
13241324
case OVERRIDING:

0 commit comments

Comments
 (0)