radix_trie: skip compare in lookup_le, lookup_ge

In _lookup_ge, where a loop "looks for an available edge or val within
the current bisection node" (to quote the code comment), the value of
index has already been modified to guarantee that it is the least
value than can be found in the non-NULL child node being
examined. Therefore, if the non-NULL child is a leaf, there's no need
to compare 'index' to anything, and the value can just be returned.

The same is true for _lookup_le with 'most' replacing 'least'.
Reviewed by:	alc
Tested by:	pho
Differential Revision:	https://reviews.freebsd.org/D40746
This commit is contained in:
Doug Moore 2023-06-27 00:42:41 -05:00
parent d8e6f4946c
commit 72c3a43b16
2 changed files with 12 additions and 8 deletions

View File

@ -560,8 +560,9 @@ pctrie_lookup_ge(struct pctrie *ptree, uint64_t index)
NULL, PCTRIE_LOCKED);
if (pctrie_isleaf(child)) {
m = pctrie_toval(child);
if (*m >= index)
return (m);
KASSERT(*m >= index,
("pctrie_lookup_ge: leaf < index"));
return (m);
} else if (child != NULL)
goto descend;
} while (slot < (PCTRIE_COUNT - 1));
@ -677,8 +678,9 @@ pctrie_lookup_le(struct pctrie *ptree, uint64_t index)
NULL, PCTRIE_LOCKED);
if (pctrie_isleaf(child)) {
m = pctrie_toval(child);
if (*m <= index)
return (m);
KASSERT(*m <= index,
("pctrie_lookup_le: leaf > index"));
return (m);
} else if (child != NULL)
goto descend;
} while (slot > 0);

View File

@ -595,8 +595,9 @@ vm_radix_lookup_ge(struct vm_radix *rtree, vm_pindex_t index)
LOCKED);
if (vm_radix_isleaf(child)) {
m = vm_radix_topage(child);
if (m->pindex >= index)
return (m);
KASSERT(m->pindex >= index,
("vm_radix_lookup_ge: leaf<index"));
return (m);
} else if (child != NULL)
goto descend;
} while (slot < (VM_RADIX_COUNT - 1));
@ -709,8 +710,9 @@ vm_radix_lookup_le(struct vm_radix *rtree, vm_pindex_t index)
LOCKED);
if (vm_radix_isleaf(child)) {
m = vm_radix_topage(child);
if (m->pindex <= index)
return (m);
KASSERT(m->pindex <= index,
("vm_radix_lookup_le: leaf>index"));
return (m);
} else if (child != NULL)
goto descend;
} while (slot > 0);