HomeFreeBSD

sysctl_search_oid: remove useless tests

Description

sysctl_search_oid: remove useless tests

sysctl_search_old makes several tests in a loop that can be removed.

The first test in the loop is only ever true on the first loop
iteration, and is always true on that iteration, so its work can be
done before the loop begins.

The upper and lower bounds on the loop variable 'indx' are each tested
on each iteration, but 'indx' is changed in one direction or the other
only once within the loop, so only one bound needs to be checked.

Two ways remain in the loop that nodes[indx] can change (after one of
them is put before the loop start), and one of them applies exactly
when indx has been incremented, so no separate test for that case
requires testing.

Restructure and add comments that makes clearer that this is a basic
depth-first search.

Reviewed by: hselasky
Differential Revision: https://reviews.freebsd.org/D36741

Details

Provenance
dougmAuthored on Sep 27 2022, 6:30 PM
Reviewer
hselasky
Differential Revision
D36741: sysctl_search_oid: remove useless tests
Parents
rGf092c21bf630: snd_uaudio(4): Add some examples accessing USB MIDI devices.
Branches
Unknown
Tags
Unknown