Skip to content

Commit

Permalink
gh-93829: In sqlite3, replace Py_BuildValue with faster APIs (#93830)
Browse files Browse the repository at this point in the history
- In Modules/_sqlite/connection.c, use PyLong_FromLong
- In Modules/_sqlite/microprotocols.c, use PyTuple_Pack
  • Loading branch information
erlend-aasland committed Jun 15, 2022
1 parent cdd3984 commit 4e9fa71
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -1582,9 +1582,8 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self
{
if (!pysqlite_check_connection(self)) {
return NULL;
} else {
return Py_BuildValue("i", sqlite3_total_changes(self->db));
}
return PyLong_FromLong(sqlite3_total_changes(self->db));
}

static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)
Expand Down
4 changes: 2 additions & 2 deletions Modules/_sqlite/microprotocols.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pysqlite_microprotocols_add(pysqlite_state *state, PyTypeObject *type,

assert(type != NULL);
assert(proto != NULL);
key = Py_BuildValue("(OO)", (PyObject*)type, proto);
key = PyTuple_Pack(2, (PyObject *)type, proto);
if (!key) {
return -1;
}
Expand All @@ -81,7 +81,7 @@ pysqlite_microprotocols_adapt(pysqlite_state *state, PyObject *obj,
way to get a quotable object to be its instance */

/* look for an adapter in the registry */
key = Py_BuildValue("(OO)", (PyObject*)Py_TYPE(obj), proto);
key = PyTuple_Pack(2, (PyObject *)Py_TYPE(obj), proto);
if (!key) {
return NULL;
}
Expand Down

0 comments on commit 4e9fa71

Please sign in to comment.