mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 04:41:11 +00:00
Bug 1932588
- Remove as much Gecko-specific and Servo-specific code as possible from malloc_size_of
r=emilio
Servo is going to maintain a fork of `malloc_size_of` internally so that Stylo does not need to have an implicit dependency on all of the crates that need an implementation of `MallocSizeOf`. In order to prepare for this, implementations that are only used in Servo should be removed (unless they are used in Stylo itself). In addition, we can remove some Gecko-specific implementations as well in order to make downstream Stylo a bit cleaner. Differential Revision: https://phabricator.services.mozilla.com/D229764
This commit is contained in:
parent
b0919598a5
commit
86f02173a4
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1607,6 +1607,7 @@ name = "dom"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"malloc_size_of",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -3733,7 +3734,6 @@ version = "0.0.1"
|
||||
dependencies = [
|
||||
"app_units",
|
||||
"cssparser",
|
||||
"dom",
|
||||
"euclid",
|
||||
"selectors",
|
||||
"servo_arc",
|
||||
|
@ -12,3 +12,4 @@ path = "lib.rs"
|
||||
|
||||
[dependencies]
|
||||
bitflags = "2"
|
||||
malloc_size_of = { path = "../../../servo/components/malloc_size_of" }
|
||||
|
@ -5,6 +5,7 @@
|
||||
//! DOM types to be shared between Rust and C++.
|
||||
|
||||
use bitflags::bitflags;
|
||||
use malloc_size_of::malloc_size_of_is_0;
|
||||
|
||||
bitflags! {
|
||||
/// Event-based element states.
|
||||
@ -163,3 +164,5 @@ bitflags! {
|
||||
const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits() | Self::RTL_LOCALE.bits();
|
||||
}
|
||||
}
|
||||
|
||||
malloc_size_of_is_0!(ElementState, DocumentState);
|
||||
|
@ -10,44 +10,17 @@ publish = false
|
||||
path = "lib.rs"
|
||||
|
||||
[features]
|
||||
servo = [
|
||||
"accountable-refcell",
|
||||
"content-security-policy",
|
||||
"crossbeam-channel",
|
||||
"http",
|
||||
"indexmap",
|
||||
"keyboard-types",
|
||||
"serde",
|
||||
"serde_bytes",
|
||||
"string_cache",
|
||||
"url",
|
||||
"uuid",
|
||||
"webrender_api",
|
||||
"xml5ever",
|
||||
]
|
||||
gecko = []
|
||||
gecko = ["thin-vec/gecko-ffi"]
|
||||
servo = ["string_cache"]
|
||||
|
||||
[dependencies]
|
||||
accountable-refcell = { version = "0.2.0", optional = true }
|
||||
app_units = "0.7"
|
||||
content-security-policy = { version = "0.4.0", features = ["serde"], optional = true }
|
||||
crossbeam-channel = { version = "0.4", optional = true }
|
||||
cssparser = "0.34"
|
||||
dom = { path = "../../../dom/base/rust" }
|
||||
euclid = "0.22"
|
||||
http = { version = "0.2", optional = true }
|
||||
indexmap = { version = "2.2", optional = true }
|
||||
keyboard-types = { version = "0.4.3", optional = true }
|
||||
selectors = { path = "../selectors" }
|
||||
serde = { version = "1.0.27", optional = true }
|
||||
serde_bytes = { version = "0.11", optional = true }
|
||||
servo_arc = { path = "../servo_arc" }
|
||||
smallbitvec = "2.3.0"
|
||||
smallvec = "1.0"
|
||||
string_cache = { version = "0.8", optional = true }
|
||||
thin-vec = { version = "0.2.1", features = ["gecko-ffi"] }
|
||||
url = { version = "2.4", optional = true }
|
||||
uuid = { version = "0.8", features = ["v4"], optional = true }
|
||||
thin-vec = { version = "0.2.1" }
|
||||
void = "1.0.2"
|
||||
webrender_api = { git = "https://github.com/servo/webrender", optional = true }
|
||||
xml5ever = { version = "0.16", optional = true }
|
||||
|
@ -46,50 +46,20 @@
|
||||
//! Note: WebRender has a reduced fork of this crate, so that we can avoid
|
||||
//! publishing this crate on crates.io.
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate accountable_refcell;
|
||||
extern crate app_units;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate content_security_policy;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate crossbeam_channel;
|
||||
extern crate cssparser;
|
||||
extern crate euclid;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate http;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate keyboard_types;
|
||||
extern crate selectors;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate serde;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate serde_bytes;
|
||||
extern crate servo_arc;
|
||||
extern crate smallbitvec;
|
||||
extern crate smallvec;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate string_cache;
|
||||
#[cfg(feature = "url")]
|
||||
extern crate url;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate uuid;
|
||||
extern crate void;
|
||||
#[cfg(feature = "webrender_api")]
|
||||
extern crate webrender_api;
|
||||
#[cfg(feature = "servo")]
|
||||
extern crate xml5ever;
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
use content_security_policy as csp;
|
||||
#[cfg(feature = "servo")]
|
||||
use serde_bytes::ByteBuf;
|
||||
use std::hash::{BuildHasher, Hash};
|
||||
use std::mem::size_of;
|
||||
use std::ops::Range;
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::os::raw::c_void;
|
||||
#[cfg(feature = "servo")]
|
||||
use uuid::Uuid;
|
||||
use void::Void;
|
||||
|
||||
/// A C function that takes a pointer to a heap allocation and returns its size.
|
||||
@ -338,24 +308,6 @@ impl<T: MallocSizeOf> MallocSizeOf for [T] {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl MallocShallowSizeOf for ByteBuf {
|
||||
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
unsafe { ops.malloc_size_of(self.as_ptr()) }
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl MallocSizeOf for ByteBuf {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
let mut n = self.shallow_size_of(ops);
|
||||
for elem in self.iter() {
|
||||
n += elem.size_of(ops);
|
||||
}
|
||||
n
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> MallocShallowSizeOf for Vec<T> {
|
||||
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
unsafe { ops.malloc_size_of(self.as_ptr()) }
|
||||
@ -863,116 +815,8 @@ malloc_size_of_is_0!(app_units::Au);
|
||||
|
||||
malloc_size_of_is_0!(cssparser::TokenSerializationType, cssparser::SourceLocation, cssparser::SourcePosition);
|
||||
|
||||
#[cfg(feature = "gecko")]
|
||||
malloc_size_of_is_0!(dom::ElementState, dom::DocumentState);
|
||||
|
||||
malloc_size_of_is_0!(selectors::OpaqueElement);
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(csp::Destination);
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(Uuid);
|
||||
|
||||
#[cfg(feature = "url")]
|
||||
impl MallocSizeOf for url::Host {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
match *self {
|
||||
url::Host::Domain(ref s) => s.size_of(ops),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::BorderRadius);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::BorderStyle);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::BoxShadowClipMode);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ColorF);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ComplexClipRegion);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ExtendMode);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::FilterOp);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ExternalScrollId);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::FontInstanceKey);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::GradientStop);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::GlyphInstance);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::NinePatchBorder);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ImageKey);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::ImageRendering);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::LineStyle);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::MixBlendMode);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::NormalBorder);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::RepeatMode);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::StickyOffsetBounds);
|
||||
#[cfg(feature = "webrender_api")]
|
||||
malloc_size_of_is_0!(webrender_api::TransformStyle);
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl MallocSizeOf for keyboard_types::Key {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
match self {
|
||||
keyboard_types::Key::Character(ref s) => s.size_of(ops),
|
||||
_ => 0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(keyboard_types::Modifiers);
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl MallocSizeOf for xml5ever::QualName {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
self.prefix.size_of(ops) + self.ns.size_of(ops) + self.local.size_of(ops)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(std::time::Duration);
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(std::time::SystemTime);
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(std::time::Instant);
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_hash_set!(indexmap::IndexSet<T, S>);
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_hash_map!(indexmap::IndexMap<K, V, S>);
|
||||
#[cfg(feature = "servo")]
|
||||
malloc_size_of_is_0!(http::StatusCode);
|
||||
|
||||
// Placeholder for unique case where internals of Sender cannot be measured.
|
||||
// malloc size of is 0 macro complains about type supplied!
|
||||
#[cfg(feature = "servo")]
|
||||
impl<T> MallocSizeOf for crossbeam_channel::Sender<T> {
|
||||
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl<T> MallocSizeOf for tokio::sync::mpsc::UnboundedSender<T> {
|
||||
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
|
||||
0
|
||||
}
|
||||
}
|
||||
|
||||
/// Measurable that defers to inner value and used to verify MallocSizeOf implementation in a
|
||||
/// struct.
|
||||
#[derive(Clone)]
|
||||
@ -991,10 +835,3 @@ impl<T: MallocSizeOf> DerefMut for Measurable<T> {
|
||||
&mut self.0
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "servo")]
|
||||
impl<T: MallocSizeOf> MallocSizeOf for accountable_refcell::RefCell<T> {
|
||||
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
|
||||
self.borrow().size_of(ops)
|
||||
}
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ uluru = "3.0"
|
||||
unicode-bidi = { version = "0.3", default-features = false }
|
||||
void = "1.0.2"
|
||||
gecko-profiler = { path = "../../../tools/profiler/rust-api" }
|
||||
url = { version = "2.5", optional = true }
|
||||
url = { version = "2.5", optional = true, features = ["serde"] }
|
||||
|
||||
[build-dependencies]
|
||||
lazy_static = "1"
|
||||
|
Loading…
Reference in New Issue
Block a user