Skip to content

gh-129926: Speed up sqlite3.Row item access #129927

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
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
12 changes: 7 additions & 5 deletions Modules/_sqlite/row.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,8 @@ equal_ignore_case(PyObject *left, PyObject *right)
if (eq) { /* equal or error */
return eq;
}
if (!PyUnicode_Check(left) || !PyUnicode_Check(right)) {
return 0;
}
assert(PyUnicode_Check(left));
assert(PyUnicode_Check(right));
if (!PyUnicode_IS_ASCII(left) || !PyUnicode_IS_ASCII(right)) {
return 0;
}
Expand Down Expand Up @@ -154,6 +153,7 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
PyErr_Format(PyExc_IndexError, "No item with key %R", idx);
return NULL;
}
assert(PyTuple_Check(self->description));
Py_ssize_t nitems = PyTuple_GET_SIZE(self->description);

for (Py_ssize_t i = 0; i < nitems; i++) {
Expand All @@ -166,8 +166,9 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
}
if (eq) {
/* found item */
PyObject *item = PyTuple_GetItem(self->data, i);
return Py_XNewRef(item);
PyObject *item = PyTuple_GET_ITEM(self->data, i);
assert(item != NULL);
return Py_NewRef(item);
}
}

Expand Down Expand Up @@ -208,6 +209,7 @@ pysqlite_row_keys_impl(pysqlite_Row *self)
return list;
}

assert(PyTuple_Check(self->description));
Py_ssize_t nitems = PyTuple_GET_SIZE(self->description);
for (Py_ssize_t i = 0; i < nitems; i++) {
PyObject *descr = PyTuple_GET_ITEM(self->description, i);
Expand Down
Loading