mirror of
https://github.com/psycopg/psycopg2.git
synced 2025-02-12 07:10:33 +03:00
Less lookups and more efficient calls in microprotocols_getquoted().
This commit is contained in:
parent
422fede38e
commit
753b580d72
|
@ -2,6 +2,8 @@
|
||||||
|
|
||||||
* Replaced PyObject_CallFunction() with *ObjArgs() where more efficient.
|
* Replaced PyObject_CallFunction() with *ObjArgs() where more efficient.
|
||||||
|
|
||||||
|
* psycopg/microprotocols.c: small optimizations.
|
||||||
|
|
||||||
2010-11-08 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
2010-11-08 Daniele Varrazzo <daniele.varrazzo@gmail.com>
|
||||||
|
|
||||||
* psycopg/microprotocols.c: use faster function to build tuples.
|
* psycopg/microprotocols.c: use faster function to build tuples.
|
||||||
|
|
|
@ -188,31 +188,42 @@ PyObject *
|
||||||
microprotocol_getquoted(PyObject *obj, connectionObject *conn)
|
microprotocol_getquoted(PyObject *obj, connectionObject *conn)
|
||||||
{
|
{
|
||||||
PyObject *res = NULL;
|
PyObject *res = NULL;
|
||||||
PyObject *tmp = microprotocols_adapt(
|
PyObject *prepare = NULL;
|
||||||
obj, (PyObject*)&isqlquoteType, NULL);
|
PyObject *adapted;
|
||||||
|
|
||||||
if (tmp != NULL) {
|
if (!(adapted = microprotocols_adapt(obj, (PyObject*)&isqlquoteType, NULL))) {
|
||||||
Dprintf("microprotocol_getquoted: adapted to %s",
|
goto exit;
|
||||||
tmp->ob_type->tp_name);
|
}
|
||||||
|
|
||||||
/* if requested prepare the object passing it the connection */
|
Dprintf("microprotocol_getquoted: adapted to %s",
|
||||||
if (PyObject_HasAttrString(tmp, "prepare") && conn) {
|
adapted->ob_type->tp_name);
|
||||||
res = PyObject_CallMethod(tmp, "prepare", "O", (PyObject*)conn);
|
|
||||||
if (res == NULL) {
|
/* if requested prepare the object passing it the connection */
|
||||||
Py_DECREF(tmp);
|
if (conn) {
|
||||||
return NULL;
|
if ((prepare = PyObject_GetAttrString(adapted, "prepare"))) {
|
||||||
}
|
res = PyObject_CallFunctionObjArgs(
|
||||||
else {
|
prepare, (PyObject *)conn, NULL);
|
||||||
|
if (res) {
|
||||||
Py_DECREF(res);
|
Py_DECREF(res);
|
||||||
|
res = NULL;
|
||||||
|
} else {
|
||||||
|
goto exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
/* call the getquoted method on tmp (that should exist because we
|
/* adapted.prepare not found */
|
||||||
adapted to the right protocol) */
|
PyErr_Clear();
|
||||||
res = PyObject_CallMethod(tmp, "getquoted", NULL);
|
}
|
||||||
Py_DECREF(tmp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* call the getquoted method on adapted (that should exist because we
|
||||||
|
adapted to the right protocol) */
|
||||||
|
res = PyObject_CallMethod(adapted, "getquoted", NULL);
|
||||||
|
|
||||||
|
exit:
|
||||||
|
Py_XDECREF(adapted);
|
||||||
|
Py_XDECREF(prepare);
|
||||||
|
|
||||||
/* we return res with one extra reference, the caller shall free it */
|
/* we return res with one extra reference, the caller shall free it */
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user