From 5c5da6071ec50b33e6a0dd8fc19d266b3c580a51 Mon Sep 17 00:00:00 2001 From: Kingsley Yung Date: Wed, 30 Apr 2025 23:19:30 +0800 Subject: [PATCH] Remove macro impl_rare_data (#36771) This macro does not hide any complex or unsafe implementation details, and, it's only used in two files (node.rs and element.rs). This patch removes the macro, and move the implementation in place. Moreover, the Element::rare_data_mut function in element.rs is called by other functions, so the #[allow(dead_code)] annotation is removed. The Node::rare_data_mut function in node.rs is not called anywhere, so it is removed. Testing: No test is needed for this cleaning up. Fixes: #36767 --------- Signed-off-by: Kingsley Yung --- components/script/dom/element.rs | 16 +++++++++++++++- components/script/dom/macros.rs | 23 ----------------------- components/script/dom/node.rs | 12 +++++++++++- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 3a8ac8f0cd8..2831fc3d8f0 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -327,7 +327,21 @@ impl Element { ) } - impl_rare_data!(ElementRareData); + fn rare_data(&self) -> Ref>> { + self.rare_data.borrow() + } + + fn rare_data_mut(&self) -> RefMut>> { + self.rare_data.borrow_mut() + } + + fn ensure_rare_data(&self) -> RefMut> { + let mut rare_data = self.rare_data.borrow_mut(); + if rare_data.is_none() { + *rare_data = Some(Default::default()); + } + RefMut::map(rare_data, |rare_data| rare_data.as_mut().unwrap()) + } pub(crate) fn restyle(&self, damage: NodeDamage) { let doc = self.node.owner_doc(); diff --git a/components/script/dom/macros.rs b/components/script/dom/macros.rs index b3f222af0da..c2f5ba37c21 100644 --- a/components/script/dom/macros.rs +++ b/components/script/dom/macros.rs @@ -719,26 +719,3 @@ macro_rules! handle_potential_webgl_error { handle_potential_webgl_error!($context, $call, ()) }; } - -macro_rules! impl_rare_data ( - ($type:ty) => ( - fn rare_data(&self) -> Ref>> { - self.rare_data.borrow() - } - - #[allow(dead_code)] - fn rare_data_mut(&self) -> RefMut>> { - self.rare_data.borrow_mut() - } - - fn ensure_rare_data(&self) -> RefMut> { - let mut rare_data = self.rare_data.borrow_mut(); - if rare_data.is_none() { - *rare_data = Some(Default::default()); - } - RefMut::map(rare_data, |rare_data| { - rare_data.as_mut().unwrap() - }) - } - ); -); diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index d312fe88fc5..1117eff6d3c 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -564,7 +564,17 @@ impl Iterator for QuerySelectorIterator { } impl Node { - impl_rare_data!(NodeRareData); + fn rare_data(&self) -> Ref>> { + self.rare_data.borrow() + } + + fn ensure_rare_data(&self) -> RefMut> { + let mut rare_data = self.rare_data.borrow_mut(); + if rare_data.is_none() { + *rare_data = Some(Default::default()); + } + RefMut::map(rare_data, |rare_data| rare_data.as_mut().unwrap()) + } /// Returns true if this node is before `other` in the same connected DOM /// tree.