aboutsummaryrefslogtreecommitdiff
path: root/src/spans.rs
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-03 10:43:06 +0100
committerMartin Fischer <martin@push-f.com>2021-12-05 02:52:36 +0100
commita7934a1dfd5735af335388b7c57f086132a57d3a (patch)
treef2d8a73dc8b46ec80282809f28399bb74463902e /src/spans.rs
parent9c3b87bf0315db6ef5107e26452cb5bfb4dffcff (diff)
spans: refactor to avoid one clone()
Diffstat (limited to 'src/spans.rs')
-rw-r--r--src/spans.rs12
1 files changed, 5 insertions, 7 deletions
diff --git a/src/spans.rs b/src/spans.rs
index 2107f20..c582457 100644
--- a/src/spans.rs
+++ b/src/spans.rs
@@ -62,7 +62,7 @@ pub struct SpanEmitter<R> {
seen_attributes: BTreeSet<String>,
emitted_tokens: VecDeque<Token<Span>>,
reader: PhantomData<R>,
- attr_in_end_tag_span: Span,
+ attr_in_end_tag_span: Option<Span>,
}
impl<R> Default for SpanEmitter<R> {
@@ -75,7 +75,7 @@ impl<R> Default for SpanEmitter<R> {
seen_attributes: BTreeSet::new(),
emitted_tokens: VecDeque::new(),
reader: PhantomData::default(),
- attr_in_end_tag_span: Span::default(),
+ attr_in_end_tag_span: None,
}
}
}
@@ -98,7 +98,7 @@ impl<R: GetPos> SpanEmitter<R> {
}
},
Some(Token::EndTag(_)) => {
- self.attr_in_end_tag_span = v.name_span.clone();
+ self.attr_in_end_tag_span = Some(v.name_span.clone());
if !self.seen_attributes.insert(k) {
self.emit_error_span(Error::DuplicateAttribute, v.name_span);
}
@@ -174,10 +174,8 @@ impl<R: GetPos> Emitter<R> for SpanEmitter<R> {
match token {
Token::EndTag(_) => {
if !self.seen_attributes.is_empty() {
- self.emit_error_span(
- Error::EndTagWithAttributes,
- self.attr_in_end_tag_span.clone(),
- );
+ let span = self.attr_in_end_tag_span.take().unwrap();
+ self.emit_error_span(Error::EndTagWithAttributes, span);
}
self.seen_attributes.clear();
}