aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMartin Fischer <martin@push-f.com>2021-12-03 10:05:55 +0100
committerMartin Fischer <martin@push-f.com>2021-12-05 02:52:36 +0100
commit2c5284aacb91e5d3aaa729f4319e368296b1d47d (patch)
tree0620a0ba8f631db5640b9205ab851e6e91a4bf6d /src
parent9f2b33c046b859007bba854b7a39f5110ab8dac3 (diff)
refactor: match btree_map::Entry instead of using and_modify closure
Diffstat (limited to 'src')
-rw-r--r--src/emitter.rs20
-rw-r--r--src/spans.rs22
2 files changed, 17 insertions, 25 deletions
diff --git a/src/emitter.rs b/src/emitter.rs
index 8f9e56d..e0ee8d9 100644
--- a/src/emitter.rs
+++ b/src/emitter.rs
@@ -1,3 +1,4 @@
+use std::collections::btree_map::Entry;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
@@ -213,19 +214,14 @@ impl<R> DefaultEmitter<R, ()> {
fn flush_current_attribute(&mut self) {
if let Some((k, v)) = self.current_attribute.take() {
match self.current_token {
- Some(Token::StartTag(ref mut tag)) => {
- let mut error = None;
- tag.attributes
- .entry(k)
- .and_modify(|_| {
- error = Some(Error::DuplicateAttribute);
- })
- .or_insert(v);
-
- if let Some(e) = error {
- self.emit_error(e);
+ Some(Token::StartTag(ref mut tag)) => match tag.attributes.entry(k) {
+ Entry::Vacant(vacant) => {
+ vacant.insert(v);
}
- }
+ Entry::Occupied(_) => {
+ self.emit_error(Error::DuplicateAttribute);
+ }
+ },
Some(Token::EndTag(_)) => {
if !self.seen_attributes.insert(k) {
self.emit_error(Error::DuplicateAttribute);
diff --git a/src/spans.rs b/src/spans.rs
index 85a64a9..ac87751 100644
--- a/src/spans.rs
+++ b/src/spans.rs
@@ -1,6 +1,6 @@
//! Source code spans.
use std::{
- collections::{BTreeSet, VecDeque},
+ collections::{btree_map::Entry, BTreeSet, VecDeque},
marker::PhantomData,
mem,
};
@@ -89,19 +89,15 @@ impl<R: GetPos> SpanEmitter<R> {
fn flush_current_attribute(&mut self) {
if let Some((k, v)) = self.current_attribute.take() {
match self.current_token {
- Some(Token::StartTag(ref mut tag)) => {
- let mut error = None;
- tag.attributes
- .entry(k)
- .and_modify(|a| {
- error = Some((Error::DuplicateAttribute, a.name_span.clone()));
- })
- .or_insert(v);
-
- if let Some((e, span)) = error {
- self.emit_error_span(e, span);
+ Some(Token::StartTag(ref mut tag)) => match tag.attributes.entry(k) {
+ Entry::Vacant(vacant) => {
+ vacant.insert(v);
}
- }
+ Entry::Occupied(occupied) => {
+ let span = occupied.get().name_span.clone();
+ self.emit_error_span(Error::DuplicateAttribute, span);
+ }
+ },
Some(Token::EndTag(_)) => {
self.attr_in_end_tag_span = v.name_span.clone();
if !self.seen_attributes.insert(k) {