Used boxed str instead of strings

This commit is contained in:
p11 2023-07-19 18:58:20 +02:00
parent 95316dc7f4
commit 33b55bf4a6

View File

@ -39,13 +39,13 @@ fn fail(mut stream: TcpStream) {
}
struct Comment {
name: String,
text: String,
name: Box<str>,
text: Box<str>,
}
#[derive(Default)]
struct Context {
comments: HashMap<String, Vec<Comment>>,
comments: HashMap<Box<str>, Vec<Comment>>,
}
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('&', "&amp;")
.replace('<', "&lt;")
.replace('>', "&gt;");
.replace('>', "&gt;")
.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 });
}