From 33b55bf4a6c1469f408f0e345bfe69435055bd53 Mon Sep 17 00:00:00 2001 From: p11 Date: Wed, 19 Jul 2023 18:58:20 +0200 Subject: [PATCH] Used boxed str instead of strings --- src/main.rs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/main.rs b/src/main.rs index 10b5854..f9b2876 100644 --- a/src/main.rs +++ b/src/main.rs @@ -39,13 +39,13 @@ fn fail(mut stream: TcpStream) { } struct Comment { - name: String, - text: String, + name: Box, + text: Box, } #[derive(Default)] struct Context { - comments: HashMap>, + comments: HashMap, Vec>, } impl Context { @@ -126,7 +126,7 @@ impl Context { }; use Entry::*; - let local_comments = match self.comments.entry(relative_path.to_string()) { + let local_comments = match self.comments.entry(relative_path.clone().into_boxed_str()) { Occupied(o) => o.into_mut(), Vacant(v) => v.insert(Vec::new()), }; @@ -144,7 +144,8 @@ impl Context { let name = decoded_name .replace('&', "&") .replace('<', "<") - .replace('>', ">"); + .replace('>', ">") + .into(); let text_value = input_text.replace('+', " "); let decoded_text = percent_decode_str(&text_value).decode_utf8_lossy(); @@ -156,7 +157,7 @@ impl Context { convert(decoded_text.lines(), &mut text_buf); let text = std::str::from_utf8(text_buf.as_slice()) .unwrap_or_default() - .to_string(); + .into(); local_comments.push(Comment { name, text }); }