summaryrefslogtreecommitdiff
path: root/contrib/btree_gist/btree_int4.c
diff options
context:
space:
mode:
authorAndres Freund2017-12-13 00:32:31 +0000
committerAndres Freund2017-12-13 00:55:37 +0000
commit101c7ee3ee847bac970c74b73b4f2858484383e5 (patch)
tree0e2c14000aa86975fbb36fb36470f54251b83b54 /contrib/btree_gist/btree_int4.c
parent4d6ad31257adaf8a51e1c4377d96afa656d9165f (diff)
Use new overflow aware integer operations.
A previous commit added inline functions that provide fast(er) and correct overflow checks for signed integer math. Use them in a significant portion of backend code. There's more to touch in both backend and frontend code, but these were the easily identifiable cases. The old overflow checks are noticeable in integer heavy workloads. A secondary benefit is that getting rid of overflow checks that rely on signed integer overflow wrapping around, will allow us to get rid of -fwrapv in the future. Which in turn slows down other code. Author: Andres Freund Discussion: https://postgr.es/m/[email protected]
Diffstat (limited to 'contrib/btree_gist/btree_int4.c')
-rw-r--r--contrib/btree_gist/btree_int4.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/contrib/btree_gist/btree_int4.c b/contrib/btree_gist/btree_int4.c
index 35bb4424379..f2b6dec6607 100644
--- a/contrib/btree_gist/btree_int4.c
+++ b/contrib/btree_gist/btree_int4.c
@@ -5,6 +5,7 @@
#include "btree_gist.h"
#include "btree_utils_num.h"
+#include "common/int.h"
typedef struct int32key
{
@@ -99,15 +100,14 @@ int4_dist(PG_FUNCTION_ARGS)
int32 r;
int32 ra;
- r = a - b;
- ra = Abs(r);
-
- /* Overflow check. */
- if (ra < 0 || (!SAMESIGN(a, b) && !SAMESIGN(r, a)))
+ if (pg_sub_s32_overflow(a, b, &r) ||
+ r == INT32_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
+ ra = Abs(r);
+
PG_RETURN_INT32(ra);
}