(&self, row_idx: usize)
| 736 | // Decorate once: fetch the cell (and parse it for numeric |
| 737 | // sorts) per row instead of per comparison. |
| 738 | let mut keyed: Vec<(usize, &str, f64)> = rows |
| 739 | .iter() |
| 740 | .map(|&row| { |
| 741 | let cell = self.table.get(row, sort.col).unwrap_or(""); |
| 742 | let num = if sort.numeric { |
| 743 | cell.parse::<f64>() |
| 744 | .ok() |
| 745 | .filter(|value| value.is_finite()) |
| 746 | .unwrap_or(f64::NAN) |
| 747 | } else { |
| 748 | f64::NAN |
| 749 | }; |
| 750 | (row, cell, num) |
| 751 | }) |
| 752 | .collect(); |
| 753 | let cmp = |a: &(usize, &str, f64), b: &(usize, &str, f64)| { |
| 754 | let ord = if sort.numeric { |
| 755 | match (a.2.is_nan(), b.2.is_nan()) { |
| 756 | (false, false) => a.2.total_cmp(&b.2), |
| 757 | (false, true) => std::cmp::Ordering::Less, |
| 758 | (true, false) => std::cmp::Ordering::Greater, |
| 759 | (true, true) => a.1.cmp(b.1), |
| 760 | } |
no test coverage detected