]> git.ipfire.org Git - thirdparty/psycopg.git/commitdiff
Use faster C mod operator in Decimal dump
authorDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 9 May 2021 21:17:59 +0000 (23:17 +0200)
committerDaniele Varrazzo <daniele.varrazzo@gmail.com>
Sun, 9 May 2021 21:27:11 +0000 (23:27 +0200)
psycopg3_c/psycopg3_c/types/numeric.pyx

index 9cbf94d9657585ec717d13931256061d8847bc02..c0d8e7224ed4355b1db3ac8f28f4a084b0afdc53 100644 (file)
@@ -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