Skip to content

Commit 276655a

Browse files
committed
Remove unreachable second empty-heap check in heappushpop()
The second PyList_GET_SIZE(heap) == 0 check in `_heapq.heappushpop()` is unreachable and redundant. The heap size is already validated at entry, and remains stable under both the GIL and the `@critical_section heap lock` in no-GIL builds. So remove the extra check to simplify the code. Signed-off-by: Yongtao Huang <yongtaoh2022@gmail.com>
1 parent cfeede8 commit 276655a

1 file changed

Lines changed: 0 additions & 5 deletions

File tree

Modules/_heapqmodule.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,6 @@ _heapq_heappushpop_impl(PyObject *module, PyObject *heap, PyObject *item)
281281
return Py_NewRef(item);
282282
}
283283

284-
if (PyList_GET_SIZE(heap) == 0) {
285-
PyErr_SetString(PyExc_IndexError, "index out of range");
286-
return NULL;
287-
}
288-
289284
returnitem = PyList_GET_ITEM(heap, 0);
290285
PyListObject *list = _PyList_CAST(heap);
291286
FT_ATOMIC_STORE_PTR_RELAXED(list->ob_item[0], Py_NewRef(item));

0 commit comments

Comments
 (0)