Used boxed str instead of strings
This commit is contained in:
parent
95316dc7f4
commit
33b55bf4a6
13
src/main.rs
13
src/main.rs
@ -39,13 +39,13 @@ fn fail(mut stream: TcpStream) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct Comment {
|
struct Comment {
|
||||||
name: String,
|
name: Box<str>,
|
||||||
text: String,
|
text: Box<str>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Context {
|
struct Context {
|
||||||
comments: HashMap<String, Vec<Comment>>,
|
comments: HashMap<Box<str>, Vec<Comment>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Context {
|
impl Context {
|
||||||
@ -126,7 +126,7 @@ impl Context {
|
|||||||
};
|
};
|
||||||
|
|
||||||
use Entry::*;
|
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(),
|
Occupied(o) => o.into_mut(),
|
||||||
Vacant(v) => v.insert(Vec::new()),
|
Vacant(v) => v.insert(Vec::new()),
|
||||||
};
|
};
|
||||||
@ -144,7 +144,8 @@ impl Context {
|
|||||||
let name = decoded_name
|
let name = decoded_name
|
||||||
.replace('&', "&")
|
.replace('&', "&")
|
||||||
.replace('<', "<")
|
.replace('<', "<")
|
||||||
.replace('>', ">");
|
.replace('>', ">")
|
||||||
|
.into();
|
||||||
|
|
||||||
let text_value = input_text.replace('+', " ");
|
let text_value = input_text.replace('+', " ");
|
||||||
let decoded_text = percent_decode_str(&text_value).decode_utf8_lossy();
|
let decoded_text = percent_decode_str(&text_value).decode_utf8_lossy();
|
||||||
@ -156,7 +157,7 @@ impl Context {
|
|||||||
convert(decoded_text.lines(), &mut text_buf);
|
convert(decoded_text.lines(), &mut text_buf);
|
||||||
let text = std::str::from_utf8(text_buf.as_slice())
|
let text = std::str::from_utf8(text_buf.as_slice())
|
||||||
.unwrap_or_default()
|
.unwrap_or_default()
|
||||||
.to_string();
|
.into();
|
||||||
|
|
||||||
local_comments.push(Comment { name, text });
|
local_comments.push(Comment { name, text });
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user