From 1c08116f10d57a3fcaf3b4f4ae5dcd3f43451525 Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Sun, 30 Apr 2023 15:59:42 +1000 Subject: [PATCH] Avoid unnecessary Vec reallocations when computing time_points --- src/intcox.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/intcox.rs b/src/intcox.rs index 4aa11f4..6378780 100644 --- a/src/intcox.rs +++ b/src/intcox.rs @@ -191,8 +191,8 @@ pub fn fit_interval_censored_cox(data_times: Matrix2xX, mut data_indep: DMa // Get time points (t_0 = 0, t_1, ..., t_m) // TODO: Reimplement Turnbull intervals - let mut time_points: Vec; - time_points = data_times.iter().copied().collect(); + let mut time_points: Vec = Vec::with_capacity(data_times.len() + 1); + time_points.extend(data_times.iter()); time_points.push(0.0); // Ensure 0 is in the list //time_points.push(f64::INFINITY); // Ensure infinity is on the list time_points.sort_by(|a, b| a.partial_cmp(b).unwrap()); // Cannot use .sort() as f64 does not implement Ord