More consistent use of TREE_* macros in AVL comparators

Where is it appropriate and obvious, use TREE_CMP(), TREE_ISIGN() and
TREE_PCMP() instead or direct comparisons. It can make the code a lot
smaller, less error prone, and easier to read.

Sponsored-by: TrueNAS
Reviewed-by: Alexander Motin <alexander.motin@TrueNAS.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Signed-off-by: Rob Norris <rob.norris@truenas.com>
Closes #18259
This commit is contained in:
Rob Norris
2026-03-04 04:08:23 +11:00
committed by GitHub
parent 0f90a797dd
commit 1e2c94a043
19 changed files with 88 additions and 199 deletions
+5 -19
View File
@@ -251,16 +251,7 @@ snapentry_compare_by_name(const void *a, const void *b)
{
const zfs_snapentry_t *se_a = a;
const zfs_snapentry_t *se_b = b;
int ret;
ret = strcmp(se_a->se_name, se_b->se_name);
if (ret < 0)
return (-1);
else if (ret > 0)
return (1);
else
return (0);
return (TREE_ISIGN(strcmp(se_a->se_name, se_b->se_name)));
}
/*
@@ -272,15 +263,10 @@ snapentry_compare_by_objsetid(const void *a, const void *b)
const zfs_snapentry_t *se_a = a;
const zfs_snapentry_t *se_b = b;
if (se_a->se_spa != se_b->se_spa)
return ((ulong_t)se_a->se_spa < (ulong_t)se_b->se_spa ? -1 : 1);
if (se_a->se_objsetid < se_b->se_objsetid)
return (-1);
else if (se_a->se_objsetid > se_b->se_objsetid)
return (1);
else
return (0);
int cmp = TREE_PCMP(se_a->se_spa, se_b->se_spa);
if (cmp != 0)
return (cmp);
return (TREE_CMP(se_a->se_objsetid, se_b->se_objsetid));
}
/*