From: Daniele Varrazzo Date: Thu, 19 Nov 2020 01:52:04 +0000 (+0000) Subject: Avoid a cython call in bool loaders X-Git-Tag: 3.0.dev0~348 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9b8ccc9d74f966bc7feeb0c896f4f27b836d6e7c;p=thirdparty%2Fpsycopg.git Avoid a cython call in bool loaders It's probably inlined, but there is still the exception handler around. --- diff --git a/psycopg3_c/psycopg3_c/types/numeric.pyx b/psycopg3_c/psycopg3_c/types/numeric.pyx index f0a020e85..ed82de3d9 100644 --- a/psycopg3_c/psycopg3_c/types/numeric.pyx +++ b/psycopg3_c/psycopg3_c/types/numeric.pyx @@ -47,6 +47,7 @@ cdef class FloatLoader(CLoader): cdef double d = PyOS_string_to_double(data, NULL, OverflowError) return PyFloat_FromDouble(d) + cdef class Float4BinaryLoader(CLoader): cdef object cload(self, const char *data, size_t length): cdef uint32_t asint = be32toh((data)[0]) @@ -65,12 +66,13 @@ cdef class Float8BinaryLoader(CLoader): cdef class BoolLoader(CLoader): cdef object cload(self, const char *data, size_t length): - return data[0] == b't' + # this creates better C than `return data[0] == b't'` + return True if data[0] == b't' else False cdef class BoolBinaryLoader(CLoader): cdef object cload(self, const char *data, size_t length): - return data[0] != b'\x00' + return True if data[0] else False cdef void register_numeric_c_loaders():