From: Daniele Varrazzo Date: Sun, 9 May 2021 21:17:59 +0000 (+0200) Subject: Use faster C mod operator in Decimal dump X-Git-Tag: 3.0.dev0~48^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=113c446fc573dc59336f8bb7fb70a22f86639530;p=thirdparty%2Fpsycopg.git Use faster C mod operator in Decimal dump --- 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