From 87a3e5e86520bfad961142f85b7933234fbca4f2 Mon Sep 17 00:00:00 2001 From: Patrick MARIE Date: Mon, 22 Feb 2021 12:55:00 +0100 Subject: [PATCH] Get rid of useless String copy. --- src/stage.rs | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/stage.rs b/src/stage.rs index 3d96245..648f7c8 100644 --- a/src/stage.rs +++ b/src/stage.rs @@ -9,9 +9,8 @@ use std::string::String; use regex::Regex; -#[derive(Debug)] +#[derive(Copy,Clone,Debug)] pub struct Stage { - stage: String, points: u32, precision: u32, factor: char, @@ -51,7 +50,6 @@ impl TryFrom<&str> for Stage { let precision = captures.get(2).unwrap().as_str().parse::().unwrap(); Ok(Stage { - stage: String::from(stage), points: points, precision: precision, factor: factor, @@ -74,6 +72,10 @@ impl Stage { factor * self.precision as i64 } + pub fn to_string(self: &Self) -> String { + format!("{}*{}{}", self.points, self.precision, self.factor) + } + pub fn time_offset_ms(self: &Self, ts: i64) -> (i64, i64) { let table_row_size_ms = self.table_row_size_ms(); let time_offset_ms = ts * 1000 % table_row_size_ms; @@ -106,15 +108,6 @@ impl Stage { } } -impl Clone for Stage { - fn clone(&self) -> Stage { - Stage { - stage: self.stage.to_string(), - ..*self - } - } -} - impl PartialEq for Stage { fn eq(&self, other: &Self) -> bool { self.points == other.points @@ -127,6 +120,6 @@ impl Eq for Stage {} impl fmt::Display for Stage { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "{}", self.table_name()) + write!(f, "{}", self.to_string()) } }