From 8344dc819480247f14fc778dbe75bae462c72717 Mon Sep 17 00:00:00 2001 From: Alex Henrie Date: Sat, 1 Feb 2020 09:45:09 -0700 Subject: [PATCH] bpo-39496: Remove redundant checks from sqlite module's while loops --- Modules/_sqlite/cursor.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 2302ca9edac2d8..06275ecb26849d 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -786,17 +786,9 @@ PyObject* pysqlite_cursor_fetchmany(pysqlite_Cursor* self, PyObject* args, PyObj return NULL; } - /* just make sure we enter the loop */ - row = Py_None; - - while (row) { - row = pysqlite_cursor_iternext(self); - if (row) { - PyList_Append(list, row); - Py_DECREF(row); - } else { - break; - } + while ((row = pysqlite_cursor_iternext(self))) { + PyList_Append(list, row); + Py_XDECREF(row); if (++counter == maxrows) { break; @@ -821,15 +813,9 @@ PyObject* pysqlite_cursor_fetchall(pysqlite_Cursor* self, PyObject* args) return NULL; } - /* just make sure we enter the loop */ - row = (PyObject*)Py_None; - - while (row) { - row = pysqlite_cursor_iternext(self); - if (row) { - PyList_Append(list, row); - Py_DECREF(row); - } + while ((row = pysqlite_cursor_iternext(self))) { + PyList_Append(list, row); + Py_XDECREF(row); } if (PyErr_Occurred()) {