Skip to content

Commit

Permalink
NodeId::new -> From<usize> for NodeId
Browse files Browse the repository at this point in the history
  • Loading branch information
emwalker committed Oct 1, 2023
1 parent f083187 commit 77ca0b7
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 8 deletions.
10 changes: 6 additions & 4 deletions src/html5_parser/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ impl From<NodeId> for usize {
}
}

impl From<usize> for NodeId {
fn from(value: usize) -> Self {
Self(value)
}
}

impl Default for &NodeId {
fn default() -> Self {
&NodeId(0)
Expand All @@ -56,10 +62,6 @@ impl NodeId {
Self(Self::ROOT_NODE)
}

pub fn new(id: usize) -> Self {
Self(id)
}

pub fn is_positive(&self) -> bool {
self.0 > 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/html5_parser/node_arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ mod tests {
let node = Node::new_element("test", HashMap::new(), HTML_NAMESPACE);
let id = arena.add_node(node);
assert_eq!(arena.nodes.len(), 1);
assert_eq!(arena.next_id, NodeId::new(1));
assert_eq!(arena.next_id, 1.into());
assert_eq!(id, NodeId::default());
}

Expand Down
4 changes: 2 additions & 2 deletions src/html5_parser/parser/adoption_agency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> Html5Parser<'a> {
} = temp_node.data
{
if name == subject && !attributes.is_empty() {
formatting_element_idx = NodeId::new(idx);
formatting_element_idx = idx.into();
formatting_element_id = node_id;
formatting_element_name = String::from(name);
formatting_element_attributes = attributes.clone();
Expand Down Expand Up @@ -105,7 +105,7 @@ impl<'a> Html5Parser<'a> {
ActiveElement::Node(node_id) => {
let node = self.document.get_node_by_id(node_id).unwrap();
if node.is_special() {
furthest_block_idx = NodeId::new(idx);
furthest_block_idx = idx.into();
furthest_block_id = node_id;
furthest_block_children = self
.document
Expand Down
2 changes: 1 addition & 1 deletion src/html5_parser/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1965,7 +1965,7 @@ impl<'a> Html5Parser<'a> {
self.parse_error("body tag not allowed in in body insertion mode");

if self.open_elements.len() == 1
|| open_elements_get!(self, NodeId::new(1)).name != "body"
|| open_elements_get!(self, NodeId::root().next()).name != "body"
{
// ignore token
return;
Expand Down

0 comments on commit 77ca0b7

Please sign in to comment.