aboutsummaryrefslogtreecommitdiffstats
path: root/src/construct/character_reference.rs
diff options
context:
space:
mode:
authorLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-20 17:19:17 +0200
committerLibravatar Titus Wormer <tituswormer@gmail.com>2022-07-20 17:19:17 +0200
commita820d849c3e20a1d72137072d70a7c8e00306f98 (patch)
treec2916ab31d6d481e0b53a06aa9b95dfcddd4163f /src/construct/character_reference.rs
parent7894ec75a7070591c3499fce1f409563c4edc7d7 (diff)
downloadmarkdown-rs-a820d849c3e20a1d72137072d70a7c8e00306f98.tar.gz
markdown-rs-a820d849c3e20a1d72137072d70a7c8e00306f98.tar.bz2
markdown-rs-a820d849c3e20a1d72137072d70a7c8e00306f98.zip
Refactor to improve allocation around strings
Diffstat (limited to 'src/construct/character_reference.rs')
-rw-r--r--src/construct/character_reference.rs10
1 files changed, 4 insertions, 6 deletions
diff --git a/src/construct/character_reference.rs b/src/construct/character_reference.rs
index ce7cd31..a4cbec1 100644
--- a/src/construct/character_reference.rs
+++ b/src/construct/character_reference.rs
@@ -121,7 +121,7 @@ impl Kind {
#[derive(Debug, Clone)]
struct Info {
/// All parsed characters.
- buffer: Vec<char>,
+ buffer: String,
/// Kind of character reference.
kind: Kind,
}
@@ -162,7 +162,7 @@ pub fn start(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
/// ```
fn open(tokenizer: &mut Tokenizer, code: Code) -> StateFnResult {
let info = Info {
- buffer: vec![],
+ buffer: String::new(),
kind: Kind::Named,
};
if let Code::Char('#') = code {
@@ -216,10 +216,8 @@ fn numeric(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnResu
fn value(tokenizer: &mut Tokenizer, code: Code, mut info: Info) -> StateFnResult {
match code {
Code::Char(';') if !info.buffer.is_empty() => {
- let unknown_named = Kind::Named == info.kind && {
- let value = info.buffer.iter().collect::<String>();
- !CHARACTER_REFERENCES.iter().any(|d| d.0 == value)
- };
+ let unknown_named = Kind::Named == info.kind
+ && !CHARACTER_REFERENCES.iter().any(|d| d.0 == info.buffer);
if unknown_named {
(State::Nok, None)