Skip to content

Commit 0637d48

Browse files
committed
Address code review
1 parent 8c3a4dc commit 0637d48

File tree

7 files changed

+35
-21
lines changed

7 files changed

+35
-21
lines changed

Include/internal/pycore_list.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ extern "C" {
1010

1111
PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
1212
extern void _PyList_DebugMallocStats(FILE *out);
13+
extern PyObject* _PyList_GetItemRef(PyObject *, Py_ssize_t i);
1314

1415
#define _PyList_ITEMS(op) _Py_RVALUE(_PyList_CAST(op)->ob_item)
1516

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: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Objects/listobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,12 @@ PyList_GetItemRef(PyObject *op, Py_ssize_t i)
391391
return item;
392392
}
393393

394+
PyObject *
395+
_PyList_GetItemRef(PyObject *op, Py_ssize_t i)
396+
{
397+
return list_get_item_ref((PyListObject *)op, i);
398+
}
399+
394400
int
395401
PyList_SetItem(PyObject *op, Py_ssize_t i,
396402
PyObject *newitem)

Python/bytecodes.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -790,16 +790,17 @@ dummy_func(
790790
// Deopt unless 0 <= sub < PyList_Size(list)
791791
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
792792
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
793-
DEOPT_IF(!LOCK_OBJECT(list));
794-
if (index >= PyList_GET_SIZE(list)) {
795-
UNLOCK_OBJECT(list);
796-
DEOPT_IF(true);
797-
}
793+
#ifdef Py_GIL_DISABLED
794+
STAT_INC(BINARY_SUBSCR, hit);
795+
PyObject *res_o = _PyList_GetItemRef(list, index);
796+
DEOPT_IF(res_o == NULL);
797+
#else
798+
DEOPT_IF(index >= PyList_GET_SIZE(list));
798799
STAT_INC(BINARY_SUBSCR, hit);
799800
PyObject *res_o = PyList_GET_ITEM(list, index);
800801
assert(res_o != NULL);
801802
Py_INCREF(res_o);
802-
UNLOCK_OBJECT(list);
803+
#endif
803804
PyStackRef_CLOSE_SPECIALIZED(sub_st, (destructor)PyObject_Free);
804805
DEAD(sub_st);
805806
PyStackRef_CLOSE(list_st);

Python/executor_cases.c.h

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

0 commit comments

Comments
 (0)