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

View file

@ -9,10 +9,8 @@ use std::cell::{BorrowError, BorrowMutError};
pub(crate) use std::cell::{Ref, RefCell, RefMut};
#[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};
#[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};

View file

@ -66,7 +66,7 @@ use xml5ever::serialize::TraversalScope::{
use crate::conversions::Convert;
use crate::dom::activation::Activatable;
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::DocumentBinding::DocumentMethods;
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
// 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."
let attr = ref_filter_map(self.attrs(), |attrs| {
let attr = Ref::filter_map(self.attrs(), |attrs| {
attrs.iter().find(|attr| {
if attr.namespace() != &ns!(xmlns) {
return false;
@ -1493,7 +1493,8 @@ impl Element {
_ => false,
}
})
});
})
.ok();
if let Some(attr) = attr {
return (**attr.value()).into();

View file

@ -31,7 +31,7 @@ pub(crate) use crate::canvas_context::*;
use crate::conversions::Convert;
use crate::dom::attr::Attr;
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::{
BlobCallback, HTMLCanvasElementMethods, RenderingContext as RootedRenderingContext,
};
@ -225,7 +225,7 @@ impl LayoutHTMLCanvasElementHelpers for LayoutDom<'_, HTMLCanvasElement> {
impl HTMLCanvasElement {
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>> {

View file

@ -10,7 +10,7 @@ use js::rust::{HandleObject, HandleValue};
use snapshot::Snapshot;
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::{
OffscreenCanvasMethods, OffscreenRenderingContext as RootedOffscreenRenderingContext,
};
@ -84,7 +84,7 @@ impl OffscreenCanvas {
}
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> {

View file

@ -8,7 +8,7 @@ use canvas_traits::webgl::{
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::WebGLRenderingContextBinding::WebGLRenderingContextConstants as constants;
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>> {
ref_filter_map(self.vertex_attribs.borrow(), |attribs| {
Ref::filter_map(self.vertex_attribs.borrow(), |attribs| {
attribs.get(index as usize)
})
.ok()
}
pub(crate) fn set_vertex_attrib_type(&self, index: u32, type_: u32) {