Skip to content

Commit 5bd7291

Browse files
authored
pythonGH-122616: Simplify LOAD_ATTR_WITH_HINT and STORE_ATTR_WITH_HINT (pythonGH-122620)
1 parent 1bb955a commit 5bd7291

File tree

3 files changed

+44
-95
lines changed

3 files changed

+44
-95
lines changed

Python/bytecodes.c

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,16 +2053,10 @@ dummy_func(
20532053
PyDictObject *dict = _PyObject_GetManagedDict(owner_o);
20542054
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries);
20552055
PyObject *name = GETITEM(FRAME_CO_NAMES, oparg>>1);
2056-
if (DK_IS_UNICODE(dict->ma_keys)) {
2057-
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
2058-
DEOPT_IF(ep->me_key != name);
2059-
attr_o = ep->me_value;
2060-
}
2061-
else {
2062-
PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
2063-
DEOPT_IF(ep->me_key != name);
2064-
attr_o = ep->me_value;
2065-
}
2056+
DEOPT_IF(!DK_IS_UNICODE(dict->ma_keys));
2057+
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
2058+
DEOPT_IF(ep->me_key != name);
2059+
attr_o = ep->me_value;
20662060
DEOPT_IF(attr_o == NULL);
20672061
STAT_INC(LOAD_ATTR, hit);
20682062
Py_INCREF(attr_o);
@@ -2214,23 +2208,14 @@ dummy_func(
22142208
DEOPT_IF(hint >= (size_t)dict->ma_keys->dk_nentries);
22152209
PyObject *old_value;
22162210
uint64_t new_version;
2217-
if (DK_IS_UNICODE(dict->ma_keys)) {
2218-
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
2219-
DEOPT_IF(ep->me_key != name);
2220-
old_value = ep->me_value;
2221-
DEOPT_IF(old_value == NULL);
2222-
new_version = _PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, PyStackRef_AsPyObjectBorrow(value));
2223-
ep->me_value = PyStackRef_AsPyObjectSteal(value);
2224-
}
2225-
else {
2226-
PyDictKeyEntry *ep = DK_ENTRIES(dict->ma_keys) + hint;
2227-
DEOPT_IF(ep->me_key != name);
2228-
old_value = ep->me_value;
2229-
DEOPT_IF(old_value == NULL);
2230-
new_version = _PyDict_NotifyEvent(tstate->interp, PyDict_EVENT_MODIFIED, dict, name, PyStackRef_AsPyObjectBorrow(value));
2231-
ep->me_value = PyStackRef_AsPyObjectSteal(value);
2232-
}
2233-
Py_DECREF(old_value);
2211+
DEOPT_IF(!DK_IS_UNICODE(dict->ma_keys));
2212+
PyDictUnicodeEntry *ep = DK_UNICODE_ENTRIES(dict->ma_keys) + hint;
2213+
DEOPT_IF(ep->me_key != name);
2214+
old_value = ep->me_value;
2215+
PyDict_WatchEvent event = old_value == NULL ? PyDict_EVENT_ADDED : PyDict_EVENT_MODIFIED;
2216+
new_version = _PyDict_NotifyEvent(tstate->interp, event, dict, name, PyStackRef_AsPyObjectBorrow(value));
2217+
ep->me_value = PyStackRef_AsPyObjectSteal(value);
2218+
Py_XDECREF(old_value);
22342219
STAT_INC(STORE_ATTR, hit);
22352220
/* Ensure dict is GC tracked if it needs to be */
22362221
if (!_PyObject_GC_IS_TRACKED(dict) && _PyObject_GC_MAY_BE_TRACKED(PyStackRef_AsPyObjectBorrow(value))) {

Python/executor_cases.c.h

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

Python/generated_cases.c.h

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

0 commit comments

Comments
 (0)