From c81ef9a9e2c4231f825ba61310f7fa1afbec32b7 Mon Sep 17 00:00:00 2001 From: onipot Date: Sat, 18 Feb 2023 08:42:06 +0100 Subject: [PATCH] cache attrs, tag name, value on Element creation - calling get_description() over and over it is a waste (depth 100) --- src/browser/tab/element/mod.rs | 40 ++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/src/browser/tab/element/mod.rs b/src/browser/tab/element/mod.rs index 95dcf2f2..2dbc953e 100644 --- a/src/browser/tab/element/mod.rs +++ b/src/browser/tab/element/mod.rs @@ -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>, + pub tag_name: String, + pub value: String, } impl<'a> Debug for Element<'a> { @@ -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, }) }