8000 gh-129926: Speed up sqlite3.Row item access by erlend-aasland · Pull Request #129927 · python/cpython · GitHub
[go: up one dir, main page]

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 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
Next Next commit
gh-129926: Speed up sqlite3.Row item access
  • Loading branch information
erlend-aasland committed Feb 10, 2025
commit ee98f2a169775048ea1c5bed547166ad49038528
10 changes: 5 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));
Copy link
Contributor

Choose a reason for hiding this comment

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

If left and right are always unicode, could we replace the PyObject_RichCompareBool with a unicode comparison such as PyUnicode_Compare for performance?

Copy link
Member

Choose a reason for hiding this comment

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

They can be subclasses, in which case PyUnicode_Compare won't trigger on custom __eq__ IIRC.

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,7 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
}
if (eq) {
/* found item */
PyObject *item = PyTuple_GetItem(self->data, i);
return Py_XNewRef(item);
return PyTuple_GET_ITEM(self->data, i);
}
}

Expand Down Expand Up @@ -208,6 +207,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
0