Simplify the inner loop of numeric division in div_var().
authorDean Rasheed <dean.a.rasheed@gmail.com>
Sun, 27 Feb 2022 10:41:12 +0000 (10:41 +0000)
committerDean Rasheed <dean.a.rasheed@gmail.com>
Sun, 27 Feb 2022 10:41:12 +0000 (10:41 +0000)
commitd996d648f333b04ae3da3c5853120f6f37601fb2
treebf1cd477a40fb26040c7b08b54fad4f9db566a0e
parente3d41d08a17549fdc60a8b9450c0511c11d666d7
Simplify the inner loop of numeric division in div_var().

In the standard numeric division algorithm, the inner loop multiplies
the divisor by the next quotient digit and subtracts that from the
working dividend. As suggested by the original code comment, the
separate "carry" and "borrow" variables (from the multiplication and
subtraction steps respectively) can be folded together into a single
variable. Doing so significantly improves performance, as well as
simplifying the code.

Dean Rasheed, reviewed by Tom Lane.

Discussion: https://postgr.es/m/CAEZATCVwsBi-ND-t82Cuuh1=8ee6jdOpzsmGN+CUZB6yjLg9jw@mail.gmail.com
src/backend/utils/adt/numeric.c