Skip to content

Commit 4e9fa71

Browse files
authoredJun 15, 2022
gh-93829: In sqlite3, replace Py_BuildValue with faster APIs (#93830)
- In Modules/_sqlite/connection.c, use PyLong_FromLong - In Modules/_sqlite/microprotocols.c, use PyTuple_Pack
1 parent cdd3984 commit 4e9fa71

File tree

2 files changed

+3
-4
lines changed

2 files changed

+3
-4
lines changed
 

‎Modules/_sqlite/connection.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -1582,9 +1582,8 @@ static PyObject* pysqlite_connection_get_total_changes(pysqlite_Connection* self
15821582
{
15831583
if (!pysqlite_check_connection(self)) {
15841584
return NULL;
1585-
} else {
1586-
return Py_BuildValue("i", sqlite3_total_changes(self->db));
15871585
}
1586+
return PyLong_FromLong(sqlite3_total_changes(self->db));
15881587
}
15891588

15901589
static PyObject* pysqlite_connection_get_in_transaction(pysqlite_Connection* self, void* unused)

‎Modules/_sqlite/microprotocols.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ pysqlite_microprotocols_add(pysqlite_state *state, PyTypeObject *type,
5757

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

8383
/* look for an adapter in the registry */
84-
key = Py_BuildValue("(OO)", (PyObject*)Py_TYPE(obj), proto);
84+
key = PyTuple_Pack(2, (PyObject *)Py_TYPE(obj), proto);
8585
if (!key) {
8686
return NULL;
8787
}

0 commit comments

Comments
 (0)