diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-06-03 19:59:26 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-03 19:59:26 (GMT) |
commit | f461a7fc3f8740b9e79e8874175115a3474e5930 (patch) | |
tree | c3338f262e91aa6468ce5be059d473bf830a0274 /Modules/_sqlite/cursor.c | |
parent | f3fa63ec75fdbb4a08a10957a5c631bf0c4a5970 (diff) | |
download | cpython-f461a7fc3f8740b9e79e8874175115a3474e5930.zip cpython-f461a7fc3f8740b9e79e8874175115a3474e5930.tar.gz cpython-f461a7fc3f8740b9e79e8874175115a3474e5930.tar.bz2 |
bpo-42862: Use functools.lru_cache iso. _sqlite.Cache in sqlite3 module (GH-24203)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Modules/_sqlite/cursor.c')
-rw-r--r-- | Modules/_sqlite/cursor.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 757c389..8073f3b 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -416,6 +416,14 @@ static int check_cursor(pysqlite_Cursor* cur) } static PyObject * +get_statement_from_cache(pysqlite_Cursor *self, PyObject *operation) +{ + PyObject *args[] = { operation, }; + PyObject *cache = self->connection->statement_cache; + return PyObject_Vectorcall(cache, args, 1, NULL); +} + +static PyObject * _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation, PyObject* second_argument) { PyObject* parameters_list = NULL; @@ -423,7 +431,6 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation PyObject* parameters = NULL; int i; int rc; - PyObject* func_args; PyObject* result; int numcols; PyObject* column_name; @@ -485,22 +492,12 @@ _pysqlite_query_execute(pysqlite_Cursor* self, int multiple, PyObject* operation Py_SETREF(self->description, Py_None); self->rowcount = 0L; - func_args = PyTuple_New(1); - if (!func_args) { - goto error; - } - if (PyTuple_SetItem(func_args, 0, Py_NewRef(operation)) != 0) { - goto error; - } - if (self->statement) { (void)pysqlite_statement_reset(self->statement); } - Py_XSETREF(self->statement, - (pysqlite_Statement *)pysqlite_cache_get(self->connection->statement_cache, func_args)); - Py_DECREF(func_args); - + PyObject *stmt = get_statement_from_cache(self, operation); + Py_XSETREF(self->statement, (pysqlite_Statement *)stmt); if (!self->statement) { goto error; } |