Skip to content

Commit ee98f2a

Browse files
gh-129926: Speed up sqlite3.Row item access
1 parent 7e6ee50 commit ee98f2a

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

Modules/_sqlite/row.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,8 @@ equal_ignore_case(PyObject *left, PyObject *right)
113113
if (eq) { /* equal or error */
114114
return eq;
115115
}
116-
if (!PyUnicode_Check(left) || !PyUnicode_Check(right)) {
117-
return 0;
118-
}
116+
assert(PyUnicode_Check(left));
117+
assert(PyUnicode_Check(right));
119118
if (!PyUnicode_IS_ASCII(left) || !PyUnicode_IS_ASCII(right)) {
120119
return 0;
121120
}
@@ -154,6 +153,7 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
154153
PyErr_Format(PyExc_IndexError, "No item with key %R", idx);
155154
return NULL;
156155
}
156+
assert(PyTuple_Check(self->description));
157157
Py_ssize_t nitems = PyTuple_GET_SIZE(self->description);
158158

159159
for (Py_ssize_t i = 0; i < nitems; i++) {
@@ -166,8 +166,7 @@ pysqlite_row_subscript(PyObject *op, PyObject *idx)
166166
}
167167
if (eq) {
168168
/* found item */
169-
PyObject *item = PyTuple_GetItem(self->data, i);
170-
return Py_XNewRef(item);
169+
return PyTuple_GET_ITEM(self->data, i);
171170
}
172171
}
173172

@@ -208,6 +207,7 @@ pysqlite_row_keys_impl(pysqlite_Row *self)
208207
return list;
209208
}
210209

210+
assert(PyTuple_Check(self->description));
211211
Py_ssize_t nitems = PyTuple_GET_SIZE(self->description);
212212
for (Py_ssize_t i = 0; i < nitems; i++) {
213213
PyObject *descr = PyTuple_GET_ITEM(self->description, i);

0 commit comments

Comments
 (0)