]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
some cleanup
authorJörg Breitbart <jerch@rockborn.de>
Tue, 9 Sep 2025 18:09:07 +0000 (20:09 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sat, 13 Sep 2025 18:10:43 +0000 (20:10 +0200)
psycopg_c/psycopg_c/_psycopg/transform.pyx

index 78b1579e4a493f827d896b7da7b00026c8f8aa8e..1f8f0d3cc30422c7f1535b7f7442cda7db94d03e 100644 (file)
@@ -443,39 +443,35 @@ cdef class Transformer:
         cdef object records = PyList_New(row1 - row0)
 
         cdef PyObject *loader  # borrowed RowLoader
-        cdef tuple brecord
         row_loaders = self._row_loaders  # avoid an incref/decref per item
 
         for row in range(row0, row1):
-            brecord = PyTuple_New(self._nfields)
+            record = PyTuple_New(self._nfields)
             for col in range(self._nfields):
-                loader = PyList_GET_ITEM(row_loaders, col)
                 attval = &(ires.tuples[row][col])
                 if attval.len == -1:  # NULL_LEN
                     pyval = None
-                elif (<RowLoader>loader).cloader is not None:
-                    pyval = (<RowLoader>loader).cloader.cload(
-                        attval.value, attval.len)
                 else:
-                    b = PyMemoryView_FromObject(
-                        ViewBuffer._from_buffer(
-                            self._pgresult,
-                            <unsigned char *>attval.value, attval.len))
-                    pyval = PyObject_CallFunctionObjArgs(
-                        (<RowLoader>loader).loadfunc, <PyObject *>b, NULL)
+                    loader = PyList_GET_ITEM(row_loaders, col)
+                    if (<RowLoader>loader).cloader is not None:
+                        pyval = (<RowLoader>loader).cloader.cload(
+                            attval.value, attval.len)
+                    else:
+                        b = PyMemoryView_FromObject(
+                                ViewBuffer._from_buffer(
+                                    self._pgresult,
+                                    <unsigned char *>attval.value,
+                                    attval.len
+                                ))
+                        pyval = PyObject_CallFunctionObjArgs(
+                            (<RowLoader>loader).loadfunc, <PyObject *>b, NULL)
                 Py_INCREF(pyval)
-                PyTuple_SET_ITEM(<object>brecord, col, pyval)
-            Py_INCREF(brecord)
-            PyList_SET_ITEM(records, row - row0, brecord)
-
-        if make_row is not tuple:
-            for i in range(row1 - row0):
-                brecord = <tuple>PyList_GET_ITEM(records, i)
+                PyTuple_SET_ITEM(record, col, pyval)
+            if make_row is not tuple:
                 record = PyObject_CallFunctionObjArgs(
-                    make_row, <PyObject *>brecord, NULL)
-                Py_INCREF(record)
-                PyList_SET_ITEM(records, i, record)
-                Py_DECREF(<object>brecord)
+                    make_row, <PyObject *>record, NULL)
+            Py_INCREF(record)
+            PyList_SET_ITEM(records, row - row0, record)
         return records
 
     def load_row(self, int row, object make_row) -> Row: