summaryrefslogtreecommitdiff
path: root/src/bin
diff options
context:
space:
mode:
authorNathan Bossart2024-02-16 20:05:36 +0000
committerNathan Bossart2024-02-16 20:05:36 +0000
commit3b42bdb47169c617cb79123c407a19d16458b49a (patch)
tree90b3448bf3d59ab3bdc5996f2bb43fc83bcfe458 /src/bin
parent6b80394781c8de17fe7cae6996476088af3c319f (diff)
Use new overflow-safe integer comparison functions.
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
Diffstat (limited to 'src/bin')
-rw-r--r--src/bin/pg_dump/pg_dump_sort.c7
-rw-r--r--src/bin/pg_upgrade/function.c12
-rw-r--r--src/bin/pg_walsummary/pg_walsummary.c8
-rw-r--r--src/bin/psql/crosstabview.c3
4 files changed, 12 insertions, 18 deletions
diff --git a/src/bin/pg_dump/pg_dump_sort.c b/src/bin/pg_dump/pg_dump_sort.c
index f358dd22b9d..8ee8a42781a 100644
--- a/src/bin/pg_dump/pg_dump_sort.c
+++ b/src/bin/pg_dump/pg_dump_sort.c
@@ -16,6 +16,7 @@
#include "postgres_fe.h"
#include "catalog/pg_class_d.h"
+#include "common/int.h"
#include "lib/binaryheap.h"
#include "pg_backup_archiver.h"
#include "pg_backup_utils.h"
@@ -1504,9 +1505,5 @@ int_cmp(void *a, void *b, void *arg)
int ai = (int) (intptr_t) a;
int bi = (int) (intptr_t) b;
- if (ai < bi)
- return -1;
- if (ai > bi)
- return 1;
- return 0;
+ return pg_cmp_s32(ai, bi);
}
diff --git a/src/bin/pg_upgrade/function.c b/src/bin/pg_upgrade/function.c
index af998f74d37..d65153de819 100644
--- a/src/bin/pg_upgrade/function.c
+++ b/src/bin/pg_upgrade/function.c
@@ -11,6 +11,7 @@
#include "access/transam.h"
#include "catalog/pg_language_d.h"
+#include "common/int.h"
#include "pg_upgrade.h"
/*
@@ -29,17 +30,16 @@ library_name_compare(const void *p1, const void *p2)
{
const char *str1 = ((const LibraryInfo *) p1)->name;
const char *str2 = ((const LibraryInfo *) p2)->name;
- int slen1 = strlen(str1);
- int slen2 = strlen(str2);
+ size_t slen1 = strlen(str1);
+ size_t slen2 = strlen(str2);
int cmp = strcmp(str1, str2);
if (slen1 != slen2)
- return slen1 - slen2;
+ return pg_cmp_size(slen1, slen2);
if (cmp != 0)
return cmp;
- else
- return ((const LibraryInfo *) p1)->dbnum -
- ((const LibraryInfo *) p2)->dbnum;
+ return pg_cmp_s32(((const LibraryInfo *) p1)->dbnum,
+ ((const LibraryInfo *) p2)->dbnum);
}
diff --git a/src/bin/pg_walsummary/pg_walsummary.c b/src/bin/pg_walsummary/pg_walsummary.c
index 1341c83c69b..485c72d9395 100644
--- a/src/bin/pg_walsummary/pg_walsummary.c
+++ b/src/bin/pg_walsummary/pg_walsummary.c
@@ -16,6 +16,7 @@
#include <limits.h>
#include "common/blkreftable.h"
+#include "common/int.h"
#include "common/logging.h"
#include "fe_utils/option_utils.h"
#include "lib/stringinfo.h"
@@ -219,12 +220,7 @@ compare_block_numbers(const void *a, const void *b)
BlockNumber aa = *(BlockNumber *) a;
BlockNumber bb = *(BlockNumber *) b;
- if (aa > bb)
- return 1;
- else if (aa == bb)
- return 0;
- else
- return -1;
+ return pg_cmp_u32(aa, bb);
}
/*
diff --git a/src/bin/psql/crosstabview.c b/src/bin/psql/crosstabview.c
index c6116b7238e..305ed4ab0a8 100644
--- a/src/bin/psql/crosstabview.c
+++ b/src/bin/psql/crosstabview.c
@@ -8,6 +8,7 @@
#include "postgres_fe.h"
#include "common.h"
+#include "common/int.h"
#include "common/logging.h"
#include "crosstabview.h"
#include "pqexpbuffer.h"
@@ -709,5 +710,5 @@ pivotFieldCompare(const void *a, const void *b)
static int
rankCompare(const void *a, const void *b)
{
- return *((const int *) a) - *((const int *) b);
+ return pg_cmp_s32(*(const int *) a, *(const int *) b);
}