mirror of
https://github.com/postgres/postgres.git
synced 2025-11-04 20:11:56 +03:00
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
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
#include "postgres.h"
|
||||
|
||||
#include "common/int.h"
|
||||
#include "nodes/pg_list.h"
|
||||
#include "port/pg_bitutils.h"
|
||||
#include "utils/memdebug.h"
|
||||
@@ -1692,11 +1693,7 @@ list_int_cmp(const ListCell *p1, const ListCell *p2)
|
||||
int v1 = lfirst_int(p1);
|
||||
int v2 = lfirst_int(p2);
|
||||
|
||||
if (v1 < v2)
|
||||
return -1;
|
||||
if (v1 > v2)
|
||||
return 1;
|
||||
return 0;
|
||||
return pg_cmp_s32(v1, v2);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -1708,9 +1705,5 @@ list_oid_cmp(const ListCell *p1, const ListCell *p2)
|
||||
Oid v1 = lfirst_oid(p1);
|
||||
Oid v2 = lfirst_oid(p2);
|
||||
|
||||
if (v1 < v2)
|
||||
return -1;
|
||||
if (v1 > v2)
|
||||
return 1;
|
||||
return 0;
|
||||
return pg_cmp_u32(v1, v2);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,7 @@
|
||||
|
||||
#include "access/htup_details.h"
|
||||
#include "common/hashfn.h"
|
||||
#include "common/int.h"
|
||||
#include "nodes/bitmapset.h"
|
||||
#include "nodes/tidbitmap.h"
|
||||
#include "storage/lwlock.h"
|
||||
@@ -1425,11 +1426,7 @@ tbm_comparator(const void *left, const void *right)
|
||||
BlockNumber l = (*((PagetableEntry *const *) left))->blockno;
|
||||
BlockNumber r = (*((PagetableEntry *const *) right))->blockno;
|
||||
|
||||
if (l < r)
|
||||
return -1;
|
||||
else if (l > r)
|
||||
return 1;
|
||||
return 0;
|
||||
return pg_cmp_u32(l, r);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user