Page MenuHomeFreeBSD

top: improve sort field storage/lookup
ClosedPublic

Authored by kevans on Oct 21 2022, 8:59 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Oct 13, 3:03 AM
Unknown Object (File)
Sep 17 2025, 1:24 AM
Unknown Object (File)
Sep 5 2025, 4:41 PM
Unknown Object (File)
Sep 4 2025, 1:00 PM
Unknown Object (File)
Aug 18 2025, 2:02 PM
Unknown Object (File)
Aug 11 2025, 11:24 AM
Unknown Object (File)
Aug 10 2025, 4:21 AM
Unknown Object (File)
Aug 9 2025, 4:01 PM

Details

Summary

Switch up comparator mapping to avoid these kinds of errors, use a
simple array of (name, comparator) pairs rather than having to maintain
entries in two separate arrays that must have matching indices.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

kevans created this revision.
pstef added a subscriber: pstef.

But the summary contains the same phrase twice, seems unintentional.

This revision is now accepted and ready to land.Oct 21 2022, 10:20 PM

But the summary contains the same phrase twice, seems unintentional.

Whoops, good shout. Just axing this entirely:

, but the
`equivalent comparator wasn't added at that time.[...]
kib added inline comments.
usr.bin/top/machine.c
1674–1675

Switch to designated initializers?

usr.bin/top/machine.c
1674–1675

It's a bit awkward since we're cross-referencing between two arrays, but yeah, good point- I'll go ahead and switch this to a simple array of string, comparator pairs

Improve underlying storage/lookup mechanism for sort orders

This revision now requires review to proceed.Feb 13 2023, 6:42 AM
kevans retitled this revision from top: fix sorting by pid (-o pid) to top: improve sort field storage/lookup.Feb 13 2023, 6:42 AM
kevans edited the summary of this revision. (Show Details)

I'm going to commit the previous version of this as a stupid simple fix to get into 13.2, but still wanted to improve this.

usr.bin/top/machine.c
236

Could this array be const?

kevans marked an inline comment as done.
kevans edited the summary of this revision. (Show Details)

Sprinkle const around, our sort data should never change

string_index (utils.c) isn't used anymore - should it be removed?

otherwise looks good to me

GC the now-unused string_index(); refresh the diff, since this has been rebased
continuously over the past three years in my local tree and the current diff in
phab may not actually apply.

string_index (utils.c) isn't used anymore - should it be removed?

otherwise looks good to me

Good shout, thanks. GC'd.

This revision is now accepted and ready to land.Aug 8 2025, 7:52 PM
This revision was automatically updated to reflect the committed changes.