Skip to content

Commit

Permalink
Replace LocalNames with Strings, change hash function (see #45)
Browse files Browse the repository at this point in the history
  • Loading branch information
cfvescovo committed Oct 31, 2022
1 parent 0a6c6f5 commit 355d560
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 29 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ selectors = "0.22.0"
smallvec = "1.9.0"
tendril = "0.4.3"
indexmap = { version = "1.9.1", optional = true }
fnv = "1.0.7"

[dependencies.getopts]
version = "0.2.21"
Expand Down
32 changes: 16 additions & 16 deletions src/element_ref/element.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,6 @@ impl<'a> Element for ElementRef<'a> {
false
}

fn is_part(&self, _name: &LocalName) -> bool {
false
}

fn is_same_type(&self, other: &Self) -> bool {
self.value().name == other.value().name
}

fn exported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

fn imported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

fn prev_sibling_element(&self) -> Option<Self> {
self.prev_siblings()
.find(|sibling| sibling.value().is_element())
Expand All @@ -71,6 +55,10 @@ impl<'a> Element for ElementRef<'a> {
&self.value().name.ns == namespace
}

fn is_same_type(&self, other: &Self) -> bool {
self.value().name == other.value().name
}

fn attr_matches(
&self,
ns: &NamespaceConstraint<&Namespace>,
Expand Down Expand Up @@ -120,6 +108,18 @@ impl<'a> Element for ElementRef<'a> {
self.value().has_class(name, case_sensitivity)
}

fn exported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

fn imported_part(&self, _: &LocalName) -> Option<LocalName> {
None
}

fn is_part(&self, _name: &LocalName) -> bool {
false
}

fn is_empty(&self) -> bool {
!self
.children()
Expand Down
16 changes: 8 additions & 8 deletions src/node.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! HTML nodes.
use fnv::{FnvHashMap as HashMap, FnvHashSet as HashSet};
use std::collections::{hash_map, hash_set};
use std::collections::{HashMap, HashSet};
use std::fmt;
use std::ops::Deref;

Expand Down Expand Up @@ -223,10 +223,10 @@ pub struct Element {
pub name: QualName,

/// The element ID.
pub id: Option<LocalName>,
pub id: Option<String>,

/// The element classes.
pub classes: HashSet<LocalName>,
pub classes: HashSet<String>,

/// The element attributes.
pub attrs: Attributes,
Expand All @@ -238,16 +238,16 @@ impl Element {
let id = attrs
.iter()
.find(|a| a.name.local.deref() == "id")
.map(|a| LocalName::from(a.value.deref()));
.map(|a| String::from(a.value.deref()));

let classes: HashSet<LocalName> = attrs
let classes: HashSet<String> = attrs
.iter()
.find(|a| a.name.local.deref() == "class")
.map_or(HashSet::new(), |a| {
.map_or(HashSet::default(), |a| {
a.value
.deref()
.split_whitespace()
.map(LocalName::from)
.map(String::from)
.collect()
});

Expand Down Expand Up @@ -300,7 +300,7 @@ impl Element {
#[allow(missing_debug_implementations)]
#[derive(Clone)]
pub struct Classes<'a> {
inner: hash_set::Iter<'a, LocalName>,
inner: hash_set::Iter<'a, String>,
}

impl<'a> Iterator for Classes<'a> {
Expand Down
10 changes: 5 additions & 5 deletions src/selector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,21 +65,21 @@ impl<'i> parser::Parser<'i> for Parser {
pub struct Simple;

impl parser::SelectorImpl for Simple {
// see: https://github.com/servo/servo/pull/19747#issuecomment-357106065
type ExtraMatchingData = String;
type AttrValue = String;
type Identifier = LocalName;
type ClassName = LocalName;
type PartName = LocalName;
type LocalName = LocalName;
type NamespacePrefix = LocalName;
type NamespaceUrl = Namespace;
type NamespacePrefix = LocalName;
type BorrowedNamespaceUrl = Namespace;
type BorrowedLocalName = LocalName;

type BorrowedLocalName = LocalName;
type NonTSPseudoClass = NonTSPseudoClass;
type PseudoElement = PseudoElement;

// see: https://github.com/servo/servo/pull/19747#issuecomment-357106065
type ExtraMatchingData = String;
type PseudoElement = PseudoElement;
}

/// Non Tree-Structural Pseudo-Class.
Expand Down

0 comments on commit 355d560

Please sign in to comment.