@@ -42,7 +42,7 @@ module _sqlite3
42
42
[clinic start generated code]*/
43
43
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
44
44
45
- PyDoc_STRVAR (pysqlite_connect__doc__ ,
45
+ PyDoc_STRVAR (module_connect_doc ,
46
46
"connect($module, /, database, timeout=5.0, detect_types=0,\n"
47
47
" isolation_level=<unrepresentable>, check_same_thread=True,\n"
48
48
" factory=ConnectionType, cached_statements=128, uri=False)\n"
@@ -54,40 +54,31 @@ PyDoc_STRVAR(pysqlite_connect__doc__,
54
54
"in RAM instead of on disk." );
55
55
56
56
#define PYSQLITE_CONNECT_METHODDEF \
57
- {"connect", _PyCFunction_CAST(module_connect), METH_VARARGS |METH_KEYWORDS, pysqlite_connect__doc__ },
57
+ {"connect", _PyCFunction_CAST(module_connect), METH_FASTCALL |METH_KEYWORDS, module_connect_doc },
58
58
59
59
static PyObject *
60
- module_connect (PyObject * self , PyObject * args , PyObject * kwargs )
60
+ module_connect (PyObject * module , PyObject * const * args , Py_ssize_t nargsf ,
61
+ PyObject * kwnames )
61
62
{
62
- /* Python seems to have no way of extracting a single keyword-arg at
63
- * C-level, so this code is redundant with the one in connection_init in
64
- * connection.c and must always be copied from there ... */
65
- static char * kwlist [] = {
66
- "database" , "timeout" , "detect_types" , "isolation_level" ,
67
- "check_same_thread" , "factory" , "cached_statements" , "uri" ,
68
- NULL
69
- };
70
- PyObject * database ;
71
- int detect_types = 0 ;
72
- PyObject * isolation_level ;
73
- PyObject * factory = NULL ;
74
- int check_same_thread = 1 ;
75
- int cached_statements ;
76
- int uri = 0 ;
77
- double timeout = 5.0 ;
78
-
79
- if (!PyArg_ParseTupleAndKeywords (args , kwargs , "O|diOiOip" , kwlist ,
80
- & database , & timeout , & detect_types ,
81
- & isolation_level , & check_same_thread ,
82
- & factory , & cached_statements , & uri ))
83
- {
84
- return NULL ;
63
+ pysqlite_state * state = pysqlite_get_state (module );
64
+ PyObject * factory = (PyObject * )state -> ConnectionType ;
65
+
66
+ static const int FACTORY_POS = 5 ;
67
+ Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
68
+ if (nargs > FACTORY_POS ) {
69
+ factory = args [FACTORY_POS ];
85
70
}
86
- if (factory == NULL ) {
87
- pysqlite_state * state = pysqlite_get_state (self );
88
- factory = (PyObject * )state -> ConnectionType ;
71
+ else if (kwnames != NULL ) {
72
+ for (Py_ssize_t i = 0 ; i < PyTuple_GET_SIZE (kwnames ); i ++ ) {
73
+ PyObject * item = PyTuple_GET_ITEM (kwnames , i ); // borrowed ref.
74
+ if (PyUnicode_CompareWithASCIIString (item , "factory" ) == 0 ) {
75
+ factory = args [nargs + i ];
76
+ break ;
77
+ }
78
+ }
89
79
}
90
- return PyObject_Call (factory , args , kwargs );
80
+
81
+ return PyObject_Vectorcall (factory , args , nargsf , kwnames );
91
82
}
92
83
93
84
/*[clinic input]
0 commit comments