Skip to content

Commit d5dc19b

Browse files
committed
apply review comments
1 parent 182858e commit d5dc19b

File tree

7 files changed

+28
-39
lines changed

7 files changed

+28
-39
lines changed

Include/internal/pycore_dict.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ extern int _PyDict_Next(
4444

4545
extern int _PyDict_HasOnlyStringKeys(PyObject *mp);
4646

47+
extern PyObject *_PyDict_Subscript(PyObject *self, PyObject *key);
48+
4749
// Export for '_ctypes' shared extension
4850
PyAPI_FUNC(Py_ssize_t) _PyDict_SizeOf(PyDictObject *);
4951

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

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

Objects/dictobject.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3388,8 +3388,8 @@ dict_length(PyObject *self)
33883388
return FT_ATOMIC_LOAD_SSIZE_RELAXED(((PyDictObject *)self)->ma_used);
33893389
}
33903390

3391-
static PyObject *
3392-
dict_subscript(PyObject *self, PyObject *key)
3391+
PyObject *
3392+
_PyDict_Subscript(PyObject *self, PyObject *key)
33933393
{
33943394
PyDictObject *mp = (PyDictObject *)self;
33953395
Py_ssize_t ix;
@@ -3434,7 +3434,7 @@ dict_ass_sub(PyObject *mp, PyObject *v, PyObject *w)
34343434

34353435
static PyMappingMethods dict_as_mapping = {
34363436
dict_length, /*mp_length*/
3437-
dict_subscript, /*mp_subscript*/
3437+
_PyDict_Subscript, /*mp_subscript*/
34383438
dict_ass_sub, /*mp_ass_subscript*/
34393439
};
34403440

@@ -4712,7 +4712,7 @@ In either case, this is followed by: for k in F: D[k] = F[k]");
47124712

47134713
static PyMethodDef mapp_methods[] = {
47144714
DICT___CONTAINS___METHODDEF
4715-
{"__getitem__", dict_subscript, METH_O | METH_COEXIST,
4715+
{"__getitem__", _PyDict_Subscript, METH_O | METH_COEXIST,
47164716
getitem__doc__},
47174717
DICT___SIZEOF___METHODDEF
47184718
DICT_GET_METHODDEF

Python/bytecodes.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -961,7 +961,9 @@ dummy_func(
961961

962962
op(_GUARD_NOS_DICT_NOT_EXACT, (nos, unused -- nos, unused)) {
963963
PyObject *o = PyStackRef_AsPyObjectBorrow(nos);
964-
EXIT_IF(!PyDict_Check(o));
964+
DEOPT_IF(!Py_TYPE(o)->tp_as_mapping);
965+
DEOPT_IF(Py_TYPE(o)->tp_as_mapping->mp_subscript !=
966+
PyDict_Type.tp_as_mapping->mp_subscript);
965967
}
966968

967969
op(_GUARD_TOS_DICT, (tos -- tos)) {
@@ -976,12 +978,8 @@ dummy_func(
976978
PyObject *sub = PyStackRef_AsPyObjectBorrow(sub_st);
977979
PyObject *dict = PyStackRef_AsPyObjectBorrow(dict_st);
978980

979-
assert(PyDict_Check(dict));
980-
DEOPT_IF(!Py_TYPE(dict)->tp_as_mapping);
981-
DEOPT_IF(Py_TYPE(dict)->tp_as_mapping->mp_subscript !=
982-
PyDict_Type.tp_as_mapping->mp_subscript);
983981
STAT_INC(BINARY_OP, hit);
984-
PyObject *res_o = PyDict_Type.tp_as_mapping->mp_subscript(dict, sub);
982+
PyObject *res_o = _PyDict_Subscript(dict, sub);
985983
DECREF_INPUTS();
986984
ERROR_IF(res_o == NULL, error); // not found or error
987985
res = PyStackRef_FromPyObjectSteal(res_o);

Python/executor_cases.c.h

Lines changed: 7 additions & 12 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: 8 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)