Skip to content

Commit 0fb6604

Browse files
author
bors-servo
committed
Auto merge of servo#6556 - frewsxcv:AttrValue-from_serialized_tokenlist, r=Ms2ger
Utilize iterators for AttrValue::from_serialized_tokenlist <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/6556) <!-- Reviewable:end -->
2 parents d3d4976 + a985ee4 commit 0fb6604

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

components/script/dom/attr.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,13 @@ pub enum AttrValue {
3838

3939
impl AttrValue {
4040
pub fn from_serialized_tokenlist(tokens: DOMString) -> AttrValue {
41-
let mut atoms: Vec<Atom> = vec!();
42-
for token in split_html_space_chars(&tokens).map(Atom::from_slice) {
43-
if !atoms.iter().any(|atom| *atom == token) {
44-
atoms.push(token);
45-
}
46-
}
41+
let atoms =
42+
split_html_space_chars(&tokens)
43+
.map(Atom::from_slice)
44+
.fold(vec![], |mut acc, atom| {
45+
if !acc.contains(&atom) { acc.push(atom) }
46+
acc
47+
});
4748
AttrValue::TokenList(tokens, atoms)
4849
}
4950

0 commit comments

Comments
 (0)