Skip to content
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));
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,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