[Python-checkins] gh-93829: In sqlite3, replace Py_BuildValue with faster APIs (#93830)

erlend-aasland webhook-mailer at python.org
Wed Jun 15 04:42:54 EDT 2022


https://github.com/python/cpython/commit/4e9fa71d7e8e2f322f0b81b315ddc921f57384c0
commit: 4e9fa71d7e8e2f322f0b81b315ddc921f57384c0
branch: main
author: Erlend Egeberg Aasland <erlend.aasland at protonmail.com>
committer: erlend-aasland <erlend.aasland at protonmail.com>
date: 2022-06-15T10:42:49+02:00
summary:

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

files:
M Modules/_sqlite/connection.c
M Modules/_sqlite/microprotocols.c

diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c
index 484af7a1771b0..f0e6a56b43a60 100644
--- a/Modules/_sqlite/connection.c
+++ b/Modules/_sqlite/connection.c
@@ -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)
diff --git a/Modules/_sqlite/microprotocols.c b/Modules/_sqlite/microprotocols.c
index a79f0067b17e8..148220d0f91f9 100644
--- a/Modules/_sqlite/microprotocols.c
+++ b/Modules/_sqlite/microprotocols.c
@@ -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;
     }
@@ -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;
     }



More information about the Python-checkins mailing list