From a820d849c3e20a1d72137072d70a7c8e00306f98 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Wed, 20 Jul 2022 17:19:17 +0200 Subject: Refactor to improve allocation around strings --- src/construct/character_reference.rs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/construct') 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, + 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::(); - !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) -- cgit