From 9b8ccc9d74f966bc7feeb0c896f4f27b836d6e7c Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Thu, 19 Nov 2020 01:52:04 +0000 Subject: [PATCH] Avoid a cython call in bool loaders It's probably inlined, but there is still the exception handler around. --- psycopg3_c/psycopg3_c/types/numeric.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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(): -- 2.47.2