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:
3
src/backend/utils/cache/relcache.c
vendored
3
src/backend/utils/cache/relcache.c
vendored
@@ -69,6 +69,7 @@
|
||||
#include "commands/policy.h"
|
||||
#include "commands/publicationcmds.h"
|
||||
#include "commands/trigger.h"
|
||||
#include "common/int.h"
|
||||
#include "miscadmin.h"
|
||||
#include "nodes/makefuncs.h"
|
||||
#include "nodes/nodeFuncs.h"
|
||||
@@ -4520,7 +4521,7 @@ AttrDefaultCmp(const void *a, const void *b)
|
||||
const AttrDefault *ada = (const AttrDefault *) a;
|
||||
const AttrDefault *adb = (const AttrDefault *) b;
|
||||
|
||||
return ada->adnum - adb->adnum;
|
||||
return pg_cmp_s16(ada->adnum, adb->adnum);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
5
src/backend/utils/cache/syscache.c
vendored
5
src/backend/utils/cache/syscache.c
vendored
@@ -29,6 +29,7 @@
|
||||
#include "catalog/pg_shdepend_d.h"
|
||||
#include "catalog/pg_shdescription_d.h"
|
||||
#include "catalog/pg_shseclabel_d.h"
|
||||
#include "common/int.h"
|
||||
#include "lib/qunique.h"
|
||||
#include "utils/catcache.h"
|
||||
#include "utils/lsyscache.h"
|
||||
@@ -676,7 +677,5 @@ oid_compare(const void *a, const void *b)
|
||||
Oid oa = *((const Oid *) a);
|
||||
Oid ob = *((const Oid *) b);
|
||||
|
||||
if (oa == ob)
|
||||
return 0;
|
||||
return (oa > ob) ? 1 : -1;
|
||||
return pg_cmp_u32(oa, ob);
|
||||
}
|
||||
|
||||
8
src/backend/utils/cache/typcache.c
vendored
8
src/backend/utils/cache/typcache.c
vendored
@@ -57,6 +57,7 @@
|
||||
#include "catalog/pg_range.h"
|
||||
#include "catalog/pg_type.h"
|
||||
#include "commands/defrem.h"
|
||||
#include "common/int.h"
|
||||
#include "executor/executor.h"
|
||||
#include "lib/dshash.h"
|
||||
#include "optimizer/optimizer.h"
|
||||
@@ -2722,12 +2723,7 @@ enum_oid_cmp(const void *left, const void *right)
|
||||
const EnumItem *l = (const EnumItem *) left;
|
||||
const EnumItem *r = (const EnumItem *) right;
|
||||
|
||||
if (l->enum_oid < r->enum_oid)
|
||||
return -1;
|
||||
else if (l->enum_oid > r->enum_oid)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
return pg_cmp_u32(l->enum_oid, r->enum_oid);
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user