Remove ref_filter_map dependency (#36857)

Instead, use the `filter_map` functions of `std::cell::Ref` and
`accountable_refcell::Ref`, which provide the same functionality as
`ref_filter_map`.

Testing: Refactoring for removing dependency. No extra test is needed.
Fixes: #36851

---------

Signed-off-by: Kingsley Yung <kingsley@kkoyung.dev>
This commit is contained in:
Kingsley Yung 2025-05-18 22:00:58 +08:00 committed by GitHub
parent edea2caec1
commit 1271dbf6ec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 15 additions and 23 deletions

11
Cargo.lock generated
View file

@ -20,9 +20,9 @@ checksum = "c71b1793ee61086797f5c80b6efa2b8ffa6d5dd703f118545808a7f2e27f7046"
[[package]] [[package]]
name = "accountable-refcell" name = "accountable-refcell"
version = "0.2.1" version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f6e2bba6f21fcf0ae382750eb6d9387c42807761fa7329d3a05fcd1334e8c3f2" checksum = "6afea9052e0b2d90e38572691d87194b2e5d8d6899b9b850b22aaab17e486252"
dependencies = [ dependencies = [
"backtrace", "backtrace",
] ]
@ -6060,12 +6060,6 @@ dependencies = [
"thiserror 2.0.9", "thiserror 2.0.9",
] ]
[[package]]
name = "ref_filter_map"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b5ceb840e4009da4841ed22a15eb49f64fdd00a2138945c5beacf506b2fb5ed"
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.11.1" version = "1.11.1"
@ -6337,7 +6331,6 @@ dependencies = [
"pixels", "pixels",
"profile_traits", "profile_traits",
"range", "range",
"ref_filter_map",
"regex", "regex",
"script_bindings", "script_bindings",
"script_layout_interface", "script_layout_interface",

View file

@ -16,7 +16,7 @@ publish = false
rust-version = "1.85.0" rust-version = "1.85.0"
[workspace.dependencies] [workspace.dependencies]
accountable-refcell = "0.2.0" accountable-refcell = "0.2.2"
aes = "0.8.4" aes = "0.8.4"
aes-gcm = "0.10.3" aes-gcm = "0.10.3"
aes-kw = { version = "0.2.1", features = ["alloc"] } aes-kw = { version = "0.2.1", features = ["alloc"] }

View file

@ -100,7 +100,6 @@ phf = "0.11"
pixels = { path = "../pixels" } pixels = { path = "../pixels" }
profile_traits = { workspace = true } profile_traits = { workspace = true }
range = { path = "../range" } range = { path = "../range" }
ref_filter_map = "1.0.1"
regex = { workspace = true } regex = { workspace = true }
script_bindings = { path = "../script_bindings" } script_bindings = { path = "../script_bindings" }
script_layout_interface = { workspace = true } script_layout_interface = { workspace = true }

View file

@ -9,10 +9,8 @@ use std::cell::{BorrowError, BorrowMutError};
pub(crate) use std::cell::{Ref, RefCell, RefMut}; pub(crate) use std::cell::{Ref, RefCell, RefMut};
#[cfg(feature = "refcell_backtrace")] #[cfg(feature = "refcell_backtrace")]
pub(crate) use accountable_refcell::{Ref, RefCell, RefMut, ref_filter_map}; pub(crate) use accountable_refcell::{Ref, RefCell, RefMut};
use malloc_size_of::{MallocConditionalSizeOf, MallocSizeOfOps}; use malloc_size_of::{MallocConditionalSizeOf, MallocSizeOfOps};
#[cfg(not(feature = "refcell_backtrace"))]
pub(crate) use ref_filter_map::ref_filter_map;
use crate::dom::bindings::root::{assert_in_layout, assert_in_script}; use crate::dom::bindings::root::{assert_in_layout, assert_in_script};

View file

@ -66,7 +66,7 @@ use xml5ever::serialize::TraversalScope::{
use crate::conversions::Convert; use crate::conversions::Convert;
use crate::dom::activation::Activatable; use crate::dom::activation::Activatable;
use crate::dom::attr::{Attr, AttrHelpersForLayout, is_relevant_attribute}; use crate::dom::attr::{Attr, AttrHelpersForLayout, is_relevant_attribute};
use crate::dom::bindings::cell::{DomRefCell, Ref, RefMut, ref_filter_map}; use crate::dom::bindings::cell::{DomRefCell, Ref, RefMut};
use crate::dom::bindings::codegen::Bindings::AttrBinding::AttrMethods; use crate::dom::bindings::codegen::Bindings::AttrBinding::AttrMethods;
use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods; use crate::dom::bindings::codegen::Bindings::DocumentBinding::DocumentMethods;
use crate::dom::bindings::codegen::Bindings::ElementBinding::{ use crate::dom::bindings::codegen::Bindings::ElementBinding::{
@ -1480,7 +1480,7 @@ impl Element {
// is "xmlns", and local name is prefix, or if prefix is null and it has an attribute // is "xmlns", and local name is prefix, or if prefix is null and it has an attribute
// whose namespace is the XMLNS namespace, namespace prefix is null, and local name is // whose namespace is the XMLNS namespace, namespace prefix is null, and local name is
// "xmlns", then return its value if it is not the empty string, and null otherwise." // "xmlns", then return its value if it is not the empty string, and null otherwise."
let attr = ref_filter_map(self.attrs(), |attrs| { let attr = Ref::filter_map(self.attrs(), |attrs| {
attrs.iter().find(|attr| { attrs.iter().find(|attr| {
if attr.namespace() != &ns!(xmlns) { if attr.namespace() != &ns!(xmlns) {
return false; return false;
@ -1493,7 +1493,8 @@ impl Element {
_ => false, _ => false,
} }
}) })
}); })
.ok();
if let Some(attr) = attr { if let Some(attr) = attr {
return (**attr.value()).into(); return (**attr.value()).into();

View file

@ -31,7 +31,7 @@ pub(crate) use crate::canvas_context::*;
use crate::conversions::Convert; use crate::conversions::Convert;
use crate::dom::attr::Attr; use crate::dom::attr::Attr;
use crate::dom::bindings::callback::ExceptionHandling; use crate::dom::bindings::callback::ExceptionHandling;
use crate::dom::bindings::cell::{DomRefCell, Ref, ref_filter_map}; use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::{ use crate::dom::bindings::codegen::Bindings::HTMLCanvasElementBinding::{
BlobCallback, HTMLCanvasElementMethods, RenderingContext as RootedRenderingContext, BlobCallback, HTMLCanvasElementMethods, RenderingContext as RootedRenderingContext,
}; };
@ -225,7 +225,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
impl HTMLCanvasElement { impl HTMLCanvasElement {
pub(crate) fn context(&self) -> Option<Ref<RenderingContext>> { pub(crate) fn context(&self) -> Option<Ref<RenderingContext>> {
ref_filter_map(self.context_mode.borrow(), |ctx| ctx.as_ref()) Ref::filter_map(self.context_mode.borrow(), |ctx| ctx.as_ref()).ok()
} }
fn get_or_init_2d_context(&self, can_gc: CanGc) -> Option<DomRoot<CanvasRenderingContext2D>> { fn get_or_init_2d_context(&self, can_gc: CanGc) -> Option<DomRoot<CanvasRenderingContext2D>> {

View file

@ -10,7 +10,7 @@ use js::rust::{HandleObject, HandleValue};
use snapshot::Snapshot; use snapshot::Snapshot;
use crate::canvas_context::{CanvasContext, OffscreenRenderingContext}; use crate::canvas_context::{CanvasContext, OffscreenRenderingContext};
use crate::dom::bindings::cell::{DomRefCell, Ref, ref_filter_map}; use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::OffscreenCanvasBinding::{ use crate::dom::bindings::codegen::Bindings::OffscreenCanvasBinding::{
OffscreenCanvasMethods, OffscreenRenderingContext as RootedOffscreenRenderingContext, OffscreenCanvasMethods, OffscreenRenderingContext as RootedOffscreenRenderingContext,
}; };
@ -84,7 +84,7 @@ impl OffscreenCanvas {
} }
pub(crate) fn context(&self) -> Option<Ref<OffscreenRenderingContext>> { pub(crate) fn context(&self) -> Option<Ref<OffscreenRenderingContext>> {
ref_filter_map(self.context.borrow(), |ctx| ctx.as_ref()) Ref::filter_map(self.context.borrow(), |ctx| ctx.as_ref()).ok()
} }
pub(crate) fn get_image_data(&self) -> Option<Snapshot> { pub(crate) fn get_image_data(&self) -> Option<Snapshot> {

View file

@ -8,7 +8,7 @@ use canvas_traits::webgl::{
ActiveAttribInfo, WebGLCommand, WebGLError, WebGLResult, WebGLVersion, WebGLVertexArrayId, ActiveAttribInfo, WebGLCommand, WebGLError, WebGLResult, WebGLVersion, WebGLVertexArrayId,
}; };
use crate::dom::bindings::cell::{DomRefCell, Ref, ref_filter_map}; use crate::dom::bindings::cell::{DomRefCell, Ref};
use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants2; use crate::dom::bindings::codegen::Bindings::WebGL2RenderingContextBinding::WebGL2RenderingContextConstants as constants2;
use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants; use crate::dom::bindings::codegen::Bindings::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
use crate::dom::bindings::root::{Dom, MutNullableDom}; use crate::dom::bindings::root::{Dom, MutNullableDom};
@ -83,9 +83,10 @@ impl VertexArrayObject {
} }
pub(crate) fn get_vertex_attrib(&self, index: u32) -> Option<Ref<VertexAttribData>> { pub(crate) fn get_vertex_attrib(&self, index: u32) -> Option<Ref<VertexAttribData>> {
ref_filter_map(self.vertex_attribs.borrow(), |attribs| { Ref::filter_map(self.vertex_attribs.borrow(), |attribs| {
attribs.get(index as usize) attribs.get(index as usize)
}) })
.ok()
} }
pub(crate) fn set_vertex_attrib_type(&self, index: u32, type_: u32) { pub(crate) fn set_vertex_attrib_type(&self, index: u32, type_: u32) {