From: henadzit Date: Fri, 7 Feb 2025 18:43:49 +0000 (+0100) Subject: perf(c): use PyObject_CallFunctionObjArgs in UUIDBinaryLoader X-Git-Tag: 3.2.5~2^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=57a3889949b582407f327764cc403ba309b83623;p=thirdparty%2Fpsycopg.git perf(c): use PyObject_CallFunctionObjArgs in UUIDBinaryLoader --- diff --git a/psycopg_c/psycopg_c/types/uuid.pyx b/psycopg_c/psycopg_c/types/uuid.pyx index 8bac18f86..e9be3b680 100644 --- a/psycopg_c/psycopg_c/types/uuid.pyx +++ b/psycopg_c/psycopg_c/types/uuid.pyx @@ -114,14 +114,25 @@ cdef class UUIDLoader(CLoader): cdef class UUIDBinaryLoader(CLoader): format = PQ_BINARY + cdef PyObject *_uuid_type + cdef object _uuid_new + cdef object _obj_setattr + cdef PyObject *_safeuuid_unknown + def __cinit__(self, oid: int, context: AdaptContext | None = None): global uuid # uuid is slow to import, lazy load it if uuid is None: import uuid + self._uuid_type = uuid.UUID + self._uuid_new = uuid.UUID.__new__ + self._obj_setattr = object.__setattr__ + self._safeuuid_unknown = uuid.SafeUUID.unknown + cdef object cload(self, const char *data, size_t length): - u = uuid.UUID.__new__(uuid.UUID) - object.__setattr__(u, 'is_safe', uuid.SafeUUID.unknown) - object.__setattr__(u, 'int', int.from_bytes(data[:length], 'big')) + cdef object int_value = int.from_bytes(data[:length], 'big') + cdef object u = PyObject_CallFunctionObjArgs(self._uuid_new, self._uuid_type, NULL) + PyObject_CallFunctionObjArgs(self._obj_setattr, u, "is_safe", self._safeuuid_unknown, NULL) + PyObject_CallFunctionObjArgs(self._obj_setattr, u, "int", int_value, NULL) return u