mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
ISSUE-23995: lazily generate unique_id for node
This commit is contained in:
parent
4fe8238b14
commit
d0c64d347d
3 changed files with 27 additions and 19 deletions
|
@ -152,8 +152,6 @@ pub struct Node {
|
|||
/// Must be sent back to the layout thread to be destroyed when this
|
||||
/// node is finalized.
|
||||
style_and_layout_data: Cell<Option<OpaqueStyleAndLayoutData>>,
|
||||
|
||||
unique_id: UniqueId,
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
@ -1006,7 +1004,20 @@ impl Node {
|
|||
}
|
||||
|
||||
pub fn unique_id(&self) -> String {
|
||||
self.unique_id.borrow().to_simple().to_string()
|
||||
let mut rare_data = self.ensure_rare_data();
|
||||
|
||||
if rare_data.unique_id.is_none() {
|
||||
let id = UniqueId::new();
|
||||
ScriptThread::save_node_id(id.borrow().to_simple().to_string());
|
||||
rare_data.unique_id = Some(id);
|
||||
}
|
||||
rare_data
|
||||
.unique_id
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.borrow()
|
||||
.to_simple()
|
||||
.to_string()
|
||||
}
|
||||
|
||||
pub fn summarize(&self) -> NodeInfo {
|
||||
|
@ -1654,7 +1665,7 @@ impl Node {
|
|||
|
||||
#[allow(unrooted_must_root)]
|
||||
fn new_(flags: NodeFlags, doc: Option<&Document>) -> Node {
|
||||
let node = Node {
|
||||
Node {
|
||||
eventtarget: EventTarget::new_inherited(),
|
||||
|
||||
parent_node: Default::default(),
|
||||
|
@ -1671,13 +1682,7 @@ impl Node {
|
|||
ranges: WeakRangeVec::new(),
|
||||
|
||||
style_and_layout_data: Cell::new(None),
|
||||
|
||||
unique_id: UniqueId::new(),
|
||||
};
|
||||
|
||||
ScriptThread::save_node_id(node.unique_id());
|
||||
|
||||
node
|
||||
}
|
||||
}
|
||||
|
||||
// https://dom.spec.whatwg.org/#concept-node-adopt
|
||||
|
@ -3122,7 +3127,7 @@ impl<'a> UnbindContext<'a> {
|
|||
}
|
||||
|
||||
/// A node's unique ID, for devtools.
|
||||
struct UniqueId {
|
||||
pub struct UniqueId {
|
||||
cell: UnsafeCell<Option<Box<Uuid>>>,
|
||||
}
|
||||
|
||||
|
|
|
@ -7,6 +7,7 @@ use crate::dom::customelementregistry::{
|
|||
CustomElementDefinition, CustomElementReaction, CustomElementState,
|
||||
};
|
||||
use crate::dom::mutationobserver::RegisteredObserver;
|
||||
use crate::dom::node::UniqueId;
|
||||
use crate::dom::shadowroot::ShadowRoot;
|
||||
use std::rc::Rc;
|
||||
|
||||
|
@ -22,6 +23,8 @@ pub struct NodeRareData {
|
|||
pub containing_shadow_root: Option<Dom<ShadowRoot>>,
|
||||
/// Registered observers for this node.
|
||||
pub mutation_observers: Vec<RegisteredObserver>,
|
||||
/// Lazily-generated Unique Id for this node.
|
||||
pub unique_id: Option<UniqueId>,
|
||||
}
|
||||
|
||||
#[derive(Default, JSTraceable, MallocSizeOf)]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue