Fork Stylo's malloc_size_of into Servo (#34332)

This is unfortuante, but it's the only way to stop making Stylo's
`malloc_size_of` depend on so many of Servo's dependencies. This is an
important step on the way toward releasing Stylo as standalone software.
When possible, we defer to the implementation of `MallocSizeOf` that is
in the base class.

One benefit of this change is that we start properly measure the size of
WebRender types, which before were always set to zero.

In addition the `Measurable` class is removed in favor of simply
manually implementing `MallocSizeOf`, which doesn't require
uncomfortably modifying the shape of data structures.

Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
Martin Robinson 2024-11-22 15:57:55 +01:00 committed by GitHub
parent 3a32af0c85
commit a3c2471344
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 1138 additions and 133 deletions

View file

@ -107,6 +107,7 @@ servo_geometry = { path = "../geometry" }
servo_rand = { path = "../rand" }
servo_url = { path = "../url" }
smallvec = { workspace = true, features = ["union"] }
style_malloc_size_of = { workspace = true }
glow = { workspace = true }
style = { workspace = true }
style_dom = { workspace = true }

View file

@ -37,6 +37,14 @@ pub struct StyleSheetInDocument {
pub owner: Dom<Element>,
}
// This is necessary because this type is contained within a Stylo type which needs
// Stylo's version of MallocSizeOf.
impl style_malloc_size_of::MallocSizeOf for StyleSheetInDocument {
fn size_of(&self, ops: &mut style_malloc_size_of::MallocSizeOfOps) -> usize {
<StyleSheetInDocument as malloc_size_of::MallocSizeOf>::size_of(self, ops)
}
}
impl fmt::Debug for StyleSheetInDocument {
fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
self.sheet.fmt(formatter)