mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2026-05-22 02:27:36 +03:00
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:
@@ -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));
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
Reference in New Issue
Block a user