You've already forked pgbackrest
mirror of
https://github.com/pgbackrest/pgbackrest.git
synced 2026-05-22 10:15:16 +02:00
Improve sort comparators.
Improve sort comparators to use branchless comparisons when possible and avoid using subtraction. Only one comparator was using subtraction and it appears there was no overflow risk since the values were pretty small. Inspired by https://www.postgresql.org/message-id/CA%2B14426g2Wa9QuUpmakwPxXFWG_1FaY0AsApkvcTBy-YfS6uaw%40mail.gmail.com.
This commit is contained in:
@@ -9,16 +9,7 @@ Test sort comparator
|
||||
static int
|
||||
testComparator(const void *item1, const void *item2)
|
||||
{
|
||||
int int1 = *(int *)item1;
|
||||
int int2 = *(int *)item2;
|
||||
|
||||
if (int1 < int2)
|
||||
return -1;
|
||||
|
||||
if (int1 > int2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return LST_COMPARATOR_CMP(*(int *)item1, *(int *)item2);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
||||
@@ -31,16 +31,7 @@ Test sort comparator
|
||||
static int
|
||||
testComparator(const void *item1, const void *item2)
|
||||
{
|
||||
int int1 = *(int *)item1;
|
||||
int int2 = *(int *)item2;
|
||||
|
||||
if (int1 < int2)
|
||||
return -1;
|
||||
|
||||
if (int1 > int2)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
return LST_COMPARATOR_CMP(*(int *)item1, *(int *)item2);
|
||||
}
|
||||
|
||||
/***********************************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user