Skip to content

Commit

Permalink
refactor: simplify partial ordering fn, clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
ClementTsang committed May 15, 2022
1 parent 8e22261 commit 580d02a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
4 changes: 2 additions & 2 deletions src/app/widgets/process_widget.rs
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ impl ProcWidget {
}

/// Marks the selected column as hidden, and automatically resets the selected column if currently selected.
pub fn hide_column(&mut self, index: usize) {
fn hide_column(&mut self, index: usize) {
if let Some(col) = self.table_state.columns.get_mut(index) {
col.is_hidden = true;

Expand All @@ -877,7 +877,7 @@ impl ProcWidget {
}

/// Marks the selected column as shown.
pub fn show_column(&mut self, index: usize) {
fn show_column(&mut self, index: usize) {
if let Some(col) = self.table_state.columns.get_mut(index) {
col.is_hidden = false;
}
Expand Down
1 change: 0 additions & 1 deletion src/canvas/components/text_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,6 @@ mod test {
use crate::app::ScrollDirection::{self, Down, Up};

#[track_caller]

fn test_get(
bar: usize, rows: usize, direction: ScrollDirection, selected: usize, force: bool,
expected_posn: usize, expected_bar: usize,
Expand Down
1 change: 1 addition & 0 deletions src/canvas/widgets/process_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl Painter {
) {
let should_get_widget_bounds = app_state.should_get_widget_bounds();
if let Some(proc_widget_state) = app_state.proc_state.widget_states.get_mut(&widget_id) {
// TODO: [PROC] this might be too aggressive...
let recalculate_column_widths =
should_get_widget_bounds || proc_widget_state.force_update;

Expand Down
9 changes: 7 additions & 2 deletions src/utils/gen_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ pub fn get_decimal_prefix(quantity: u64, unit: &str) -> (f64, String) {
}
}

#[inline]
pub fn sort_partial_fn<T: std::cmp::PartialOrd>(is_reverse: bool) -> fn(T, T) -> Ordering {
if is_reverse {
partial_ordering_rev
Expand All @@ -101,15 +102,19 @@ pub fn sort_partial_fn<T: std::cmp::PartialOrd>(is_reverse: bool) -> fn(T, T) ->
}

/// Returns an [`Ordering`] between two [`PartialOrd`]s.
#[inline]
pub fn partial_ordering<T: std::cmp::PartialOrd>(a: T, b: T) -> Ordering {
// TODO: Switch to `total_cmp` on 1.62
a.partial_cmp(&b).unwrap_or(Ordering::Equal)
}

/// Returns a reversed [`Ordering`] between two [`PartialOrd`]s.
///
/// This is simply a wrapper function around [`partial_ordering`] that reverses
/// the result.
#[inline]
pub fn partial_ordering_rev<T: std::cmp::PartialOrd>(a: T, b: T) -> Ordering {
// TODO: Switch to `total_cmp` on 1.62
a.partial_cmp(&b).unwrap_or(Ordering::Equal).reverse()
partial_ordering(a, b).reverse()
}

#[cfg(test)]
Expand Down

0 comments on commit 580d02a

Please sign in to comment.