From 113c446fc573dc59336f8bb7fb70a22f86639530 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Sun, 9 May 2021 23:17:59 +0200 Subject: [PATCH] Use faster C mod operator in Decimal dump --- psycopg3_c/psycopg3_c/types/numeric.pyx | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/psycopg3_c/psycopg3_c/types/numeric.pyx b/psycopg3_c/psycopg3_c/types/numeric.pyx index 9cbf94d96..c0d8e7224 100644 --- a/psycopg3_c/psycopg3_c/types/numeric.pyx +++ b/psycopg3_c/psycopg3_c/types/numeric.pyx @@ -544,6 +544,7 @@ static const int pydigit_weights[] = {1000, 100, 10, 1}; const int[4] pydigit_weights @cython.final +@cython.cdivision(True) cdef class DecimalBinaryDumper(CDumper): format = PQ_BINARY @@ -609,6 +610,9 @@ cdef class DecimalBinaryDumper(CDumper): # but without changing the digits tuple. cdef int wi = 0 cdef int mod = (ndigits - dscale) % DEC_DIGITS + if mod < 0: + # the difference between C and Py % operator + mod += 4 if mod: wi = DEC_DIGITS - mod ndigits += wi -- 2.47.2