From 3b42bdb47169c617cb79123c407a19d16458b49a Mon Sep 17 00:00:00 2001 From: Nathan Bossart Date: Fri, 16 Feb 2024 14:05:36 -0600 Subject: Use new overflow-safe integer comparison functions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Commit 6b80394781 introduced integer comparison functions designed to be as efficient as possible while avoiding overflow. This commit makes use of these functions in many of the in-tree qsort() comparators to help ensure transitivity. Many of these comparator functions should also see a small performance boost. Author: Mats Kindahl Reviewed-by: Andres Freund, Fabrízio de Royes Mello Discussion: https://postgr.es/m/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com --- src/backend/utils/adt/tsgistidx.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src/backend/utils/adt/tsgistidx.c') diff --git a/src/backend/utils/adt/tsgistidx.c b/src/backend/utils/adt/tsgistidx.c index a62b285365a..3fb76964343 100644 --- a/src/backend/utils/adt/tsgistidx.c +++ b/src/backend/utils/adt/tsgistidx.c @@ -17,6 +17,7 @@ #include "access/gist.h" #include "access/heaptoast.h" #include "access/reloptions.h" +#include "common/int.h" #include "lib/qunique.h" #include "port/pg_bitutils.h" #include "tsearch/ts_utils.h" @@ -136,9 +137,7 @@ compareint(const void *va, const void *vb) int32 a = *((const int32 *) va); int32 b = *((const int32 *) vb); - if (a == b) - return 0; - return (a > b) ? 1 : -1; + return pg_cmp_s32(a, b); } static void @@ -598,10 +597,7 @@ comparecost(const void *va, const void *vb) const SPLITCOST *a = (const SPLITCOST *) va; const SPLITCOST *b = (const SPLITCOST *) vb; - if (a->cost == b->cost) - return 0; - else - return (a->cost > b->cost) ? 1 : -1; + return pg_cmp_s32(a->cost, b->cost); } -- cgit v1.2.3