Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Address code review
  • Loading branch information
corona10 committed Nov 30, 2024
commit 0637d486d22d4d33ad0ed130b7c9daaea4de061e
1 change: 1 addition & 0 deletions Include/internal/pycore_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ extern "C" {

PyAPI_FUNC(PyObject*) _PyList_Extend(PyListObject *, PyObject *);
extern void _PyList_DebugMallocStats(FILE *out);
extern PyObject* _PyList_GetItemRef(PyObject *, Py_ssize_t i);
Comment thread
mpage marked this conversation as resolved.
Outdated

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

Expand Down
2 changes: 1 addition & 1 deletion Include/internal/pycore_opcode_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Include/internal/pycore_uop_metadata.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,12 @@ PyList_GetItemRef(PyObject *op, Py_ssize_t i)
return item;
}

PyObject *
_PyList_GetItemRef(PyObject *op, Py_ssize_t i)
{
return list_get_item_ref((PyListObject *)op, i);
}

Comment thread
mpage marked this conversation as resolved.
int
PyList_SetItem(PyObject *op, Py_ssize_t i,
PyObject *newitem)
Expand Down
13 changes: 7 additions & 6 deletions Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -790,16 +790,17 @@ dummy_func(
// Deopt unless 0 <= sub < PyList_Size(list)
DEOPT_IF(!_PyLong_IsNonNegativeCompact((PyLongObject *)sub));
Py_ssize_t index = ((PyLongObject*)sub)->long_value.ob_digit[0];
DEOPT_IF(!LOCK_OBJECT(list));
if (index >= PyList_GET_SIZE(list)) {
UNLOCK_OBJECT(list);
DEOPT_IF(true);
}
#ifdef Py_GIL_DISABLED
STAT_INC(BINARY_SUBSCR, hit);
Comment thread
mpage marked this conversation as resolved.
Outdated
PyObject *res_o = _PyList_GetItemRef(list, index);
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The default build of list_get_item_ref is almost same as current implementation,
we might able to this implementation to the default build also.

#else
static inline PyObject*
list_get_item_ref(PyListObject *op, Py_ssize_t i)
{
if (!valid_index(i, Py_SIZE(op))) {
return NULL;
}
return Py_NewRef(PyList_GET_ITEM(op, i));
}
#endif

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would certainly be cleaner, but it might come with some performance cost in the default build.

Comment thread
mpage marked this conversation as resolved.
Outdated
DEOPT_IF(res_o == NULL);
#else
DEOPT_IF(index >= PyList_GET_SIZE(list));
STAT_INC(BINARY_SUBSCR, hit);
PyObject *res_o = PyList_GET_ITEM(list, index);
assert(res_o != NULL);
Py_INCREF(res_o);
Comment thread
corona10 marked this conversation as resolved.
UNLOCK_OBJECT(list);
#endif
PyStackRef_CLOSE_SPECIALIZED(sub_st, (destructor)PyObject_Free);
DEAD(sub_st);
PyStackRef_CLOSE(list_st);
Expand Down
17 changes: 10 additions & 7 deletions Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 9 additions & 6 deletions Python/generated_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.