Skip to content

Commit

Permalink
cache attrs, tag name, value on Element creation (#377)
Browse files Browse the repository at this point in the history
- calling get_description() over and over it is a waste (depth 100)
  • Loading branch information
masc-it committed Feb 20, 2023
1 parent 9ccfde8 commit 3aa701f
Showing 1 changed file with 24 additions and 16 deletions.
40 changes: 24 additions & 16 deletions src/browser/tab/element/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ pub struct Element<'a> {
pub backend_node_id: DOM::NodeId,
pub node_id: DOM::NodeId,
pub parent: &'a super::Tab,
pub attributes: Option<Vec<String>>,
pub tag_name: String,
pub value: String,
}

impl<'a> Debug for Element<'a> {
Expand All @@ -49,28 +52,33 @@ impl<'a> Element<'a> {
return Err(NoElementFound {}.into());
}

let backend_node_id = parent
.describe_node(node_id)
.map_err(NoElementFound::map)?
.backend_node_id;

let remote_object_id = {
let object = parent
.call_method(DOM::ResolveNode {
backend_node_id: Some(backend_node_id),
node_id: None,
object_group: None,
execution_context_id: None,
})?
.object;
object.object_id.expect("couldn't find object ID")
};
let node = parent.describe_node(node_id).map_err(NoElementFound::map)?;

let attributes = node.attributes;
let tag_name = node.node_name;

let backend_node_id = node.backend_node_id;

let object = parent
.call_method(DOM::ResolveNode {
backend_node_id: Some(backend_node_id),
node_id: None,
object_group: None,
execution_context_id: None,
})?
.object;

let value = object.value.unwrap_or("".into()).to_string();
let remote_object_id = object.object_id.expect("couldn't find object ID");

Ok(Element {
remote_object_id,
backend_node_id,
node_id,
parent,
attributes,
tag_name,
value,
})
}

Expand Down

0 comments on commit 3aa701f

Please sign in to comment.