1
0
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:
David Steele
2024-03-08 10:07:03 +13:00
committed by GitHub
parent e00bfe2d2c
commit 4387250f2e
7 changed files with 38 additions and 42 deletions
+1 -10
View File
@@ -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);
}
/***********************************************************************************************************************************
+1 -10
View File
@@ -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);
}
/***********************************************************************************************************************************