Reduce nesting in phn_merge_siblings using an early return.

This commit is contained in:
Amaury Séchet
2023-10-25 00:36:08 +00:00
committed by Qi Wang
parent 10d713151d
commit 92aa52c062

View File

@@ -162,6 +162,10 @@ phn_merge_siblings(void *phn, size_t offset, ph_cmp_t cmp) {
void *phn0 = phn; void *phn0 = phn;
void *phn1 = phn_next_get(phn0, offset); void *phn1 = phn_next_get(phn0, offset);
if (phn1 == NULL) {
return phn0;
}
/* /*
* Multipass merge, wherein the first two elements of a FIFO * Multipass merge, wherein the first two elements of a FIFO
* are repeatedly merged, and each result is appended to the * are repeatedly merged, and each result is appended to the
@@ -170,7 +174,6 @@ phn_merge_siblings(void *phn, size_t offset, ph_cmp_t cmp) {
* its tail, so we do a single pass over the sibling list to * its tail, so we do a single pass over the sibling list to
* populate the FIFO. * populate the FIFO.
*/ */
if (phn1 != NULL) {
void *phnrest = phn_next_get(phn1, offset); void *phnrest = phn_next_get(phn1, offset);
if (phnrest != NULL) { if (phnrest != NULL) {
phn_prev_set(phnrest, NULL, offset); phn_prev_set(phnrest, NULL, offset);
@@ -225,7 +228,7 @@ phn_merge_siblings(void *phn, size_t offset, ph_cmp_t cmp) {
phn1 = phn_next_get(phn0, offset); phn1 = phn_next_get(phn0, offset);
} }
} }
}
return phn0; return phn0;
} }