From 69f4c79ee4d426268d867221d8c2dbadf773190f Mon Sep 17 00:00:00 2001 From: Joshua Thijssen Date: Tue, 25 Jun 2024 09:29:40 +0200 Subject: [PATCH] Small fixups --- crates/gosub_css3/src/tokenizer.rs | 2 +- crates/gosub_html5/src/tokenizer.rs | 49 ++++++++++++----------------- 2 files changed, 21 insertions(+), 30 deletions(-) diff --git a/crates/gosub_css3/src/tokenizer.rs b/crates/gosub_css3/src/tokenizer.rs index c0a215d37..5e015ff0e 100644 --- a/crates/gosub_css3/src/tokenizer.rs +++ b/crates/gosub_css3/src/tokenizer.rs @@ -904,7 +904,7 @@ impl<'stream> Tokenizer<'stream> { self.stream.seek(start); // todo: this is not efficient - let mut s = String::new(); + let mut s = String::with_capacity(end - start); for c in self.stream.get_slice(end - start) { if let Ch(c) = c { s.push(*c); diff --git a/crates/gosub_html5/src/tokenizer.rs b/crates/gosub_html5/src/tokenizer.rs index 9cf98b1c6..8dc239347 100644 --- a/crates/gosub_html5/src/tokenizer.rs +++ b/crates/gosub_html5/src/tokenizer.rs @@ -335,16 +335,13 @@ impl<'stream> Tokenizer<'stream> { } State::RCDATALessThanSign => { let c = self.read_char(); - match c { - Ch('/') => { - self.temporary_buffer.clear(); - self.state = State::RCDATAEndTagOpen; - } - _ => { - self.consume('<'); - self.stream_prev(); - self.state = State::RCDATA; - } + if let Ch('/') = c { + self.temporary_buffer.clear(); + self.state = State::RCDATAEndTagOpen; + } else { + self.consume('<'); + self.stream_prev(); + self.state = State::RCDATA; } } State::RCDATAEndTagOpen => { @@ -424,16 +421,13 @@ impl<'stream> Tokenizer<'stream> { } State::RAWTEXTLessThanSign => { let c = self.read_char(); - match c { - Ch('/') => { - self.temporary_buffer.clear(); - self.state = State::RAWTEXTEndTagOpen; - } - _ => { - self.consume('<'); - self.stream_prev(); - self.state = State::RAWTEXT; - } + if let Ch('/') = c { + self.temporary_buffer.clear(); + self.state = State::RAWTEXTEndTagOpen; + } else { + self.consume('<'); + self.stream_prev(); + self.state = State::RAWTEXT; } } State::RAWTEXTEndTagOpen => { @@ -1998,15 +1992,12 @@ impl<'stream> Tokenizer<'stream> { } State::CDATASectionBracket => { let c = self.read_char(); - match c { - Ch(']') => { - self.state = State::CDATASectionEnd; - } - _ => { - self.consume(']'); - self.stream_prev(); - self.state = State::CDATASection; - } + if let Ch(']') = c { + self.state = State::CDATASectionEnd; + } else { + self.consume(']'); + self.stream_prev(); + self.state = State::CDATASection; } } State::CDATASectionEnd => {