Skip to content

Commit 639802f

Browse files
authoredNov 22, 2024··
Remove Servo-specific code from malloc_size_of (#91)
Servo will use a forked version of `malloc_size_of` so that it does not push depenencies down into Stylo. Corresponding upstream change: https://phabricator.services.mozilla.com/D229764 Signed-off-by: Martin Robinson <mrobinson@igalia.com>
1 parent 6605bdb commit 639802f

File tree

5 files changed

+6
-192
lines changed

5 files changed

+6
-192
lines changed
 

‎dom/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ path = "lib.rs"
1111

1212
[dependencies]
1313
bitflags = "2"
14+
malloc_size_of = { path = "../malloc_size_of" }

‎dom/lib.rs

+3
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
44

55
use bitflags::bitflags;
6+
use malloc_size_of::malloc_size_of_is_0;
67

78
// DOM types to be shared between Rust and C++.
89
bitflags! {
@@ -159,3 +160,5 @@ bitflags! {
159160
const ALL_LOCALEDIR_BITS = Self::LTR_LOCALE.bits() | Self::RTL_LOCALE.bits();
160161
}
161162
}
163+
164+
malloc_size_of_is_0!(ElementState, DocumentState);

‎malloc_size_of/Cargo.toml

+1-29
Original file line numberDiff line numberDiff line change
@@ -10,45 +10,17 @@ publish = false
1010
path = "lib.rs"
1111

1212
[features]
13-
servo = [
14-
"accountable-refcell",
15-
"content-security-policy",
16-
"crossbeam-channel",
17-
"http",
18-
"indexmap",
19-
"keyboard-types",
20-
"serde",
21-
"serde_bytes",
22-
"string_cache",
23-
"url",
24-
"uuid",
25-
"webrender_api",
26-
"xml5ever",
27-
]
2813
gecko = ["thin-vec/gecko-ffi"]
14+
servo = ["string_cache"]
2915

3016
[dependencies]
31-
accountable-refcell = { version = "0.2.0", optional = true }
3217
app_units = "0.7"
33-
content-security-policy = { version = "0.5", features = ["serde"], optional = true }
34-
crossbeam-channel = { version = "0.5", optional = true }
3518
cssparser = "0.34"
36-
dom = { path = "../dom" }
3719
euclid = "0.22"
38-
http = { version = "0.2", optional = true }
39-
indexmap = { version = "2.2", optional = true }
40-
keyboard-types = { version = "0.7", optional = true }
4120
selectors = { path = "../selectors" }
42-
serde = { version = "1.0.195", optional = true }
43-
serde_bytes = { version = "0.11", optional = true }
4421
servo_arc = { path = "../servo_arc" }
4522
smallbitvec = "2.3.0"
4623
smallvec = "1.13"
4724
string_cache = { version = "0.8", optional = true }
4825
thin-vec = { version = "0.2.13" }
49-
tokio = { version = "1", features = ["sync"] }
50-
url = { version = "2.5", features = ["serde"], optional = true }
51-
uuid = { version = "1.7.0", optional = true }
5226
void = "1.0.2"
53-
webrender_api = { git = "https://github.com/servo/webrender", branch = "0.65", optional = true }
54-
xml5ever = { version = "0.20", optional = true }

‎malloc_size_of/lib.rs

-162
Original file line numberDiff line numberDiff line change
@@ -46,50 +46,20 @@
4646
//! Note: WebRender has a reduced fork of this crate, so that we can avoid
4747
//! publishing this crate on crates.io.
4848
49-
#[cfg(feature = "servo")]
50-
extern crate accountable_refcell;
5149
extern crate app_units;
52-
#[cfg(feature = "servo")]
53-
extern crate content_security_policy;
54-
#[cfg(feature = "servo")]
55-
extern crate crossbeam_channel;
5650
extern crate cssparser;
5751
extern crate euclid;
58-
#[cfg(feature = "servo")]
59-
extern crate http;
60-
#[cfg(feature = "servo")]
61-
extern crate keyboard_types;
6252
extern crate selectors;
63-
#[cfg(feature = "servo")]
64-
extern crate serde;
65-
#[cfg(feature = "servo")]
66-
extern crate serde_bytes;
6753
extern crate servo_arc;
6854
extern crate smallbitvec;
6955
extern crate smallvec;
70-
#[cfg(feature = "servo")]
71-
extern crate string_cache;
72-
#[cfg(feature = "url")]
73-
extern crate url;
74-
#[cfg(feature = "servo")]
75-
extern crate uuid;
7656
extern crate void;
77-
#[cfg(feature = "webrender_api")]
78-
extern crate webrender_api;
79-
#[cfg(feature = "servo")]
80-
extern crate xml5ever;
8157

82-
#[cfg(feature = "servo")]
83-
use content_security_policy as csp;
84-
#[cfg(feature = "servo")]
85-
use serde_bytes::ByteBuf;
8658
use std::hash::{BuildHasher, Hash};
8759
use std::mem::size_of;
8860
use std::ops::Range;
8961
use std::ops::{Deref, DerefMut};
9062
use std::os::raw::c_void;
91-
#[cfg(feature = "servo")]
92-
use uuid::Uuid;
9363
use void::Void;
9464

9565
/// 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] {
338308
}
339309
}
340310

341-
#[cfg(feature = "servo")]
342-
impl MallocShallowSizeOf for ByteBuf {
343-
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
344-
unsafe { ops.malloc_size_of(self.as_ptr()) }
345-
}
346-
}
347-
348-
#[cfg(feature = "servo")]
349-
impl MallocSizeOf for ByteBuf {
350-
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
351-
let mut n = self.shallow_size_of(ops);
352-
for elem in self.iter() {
353-
n += elem.size_of(ops);
354-
}
355-
n
356-
}
357-
}
358-
359311
impl<T> MallocShallowSizeOf for Vec<T> {
360312
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
361313
unsafe { ops.malloc_size_of(self.as_ptr()) }
@@ -863,115 +815,8 @@ malloc_size_of_is_0!(app_units::Au);
863815

864816
malloc_size_of_is_0!(cssparser::TokenSerializationType, cssparser::SourceLocation, cssparser::SourcePosition);
865817

866-
malloc_size_of_is_0!(dom::ElementState, dom::DocumentState);
867-
868818
malloc_size_of_is_0!(selectors::OpaqueElement);
869819

870-
#[cfg(feature = "servo")]
871-
malloc_size_of_is_0!(csp::Destination);
872-
873-
#[cfg(feature = "servo")]
874-
malloc_size_of_is_0!(Uuid);
875-
876-
#[cfg(feature = "url")]
877-
impl MallocSizeOf for url::Host {
878-
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
879-
match *self {
880-
url::Host::Domain(ref s) => s.size_of(ops),
881-
_ => 0,
882-
}
883-
}
884-
}
885-
#[cfg(feature = "webrender_api")]
886-
malloc_size_of_is_0!(webrender_api::BorderRadius);
887-
#[cfg(feature = "webrender_api")]
888-
malloc_size_of_is_0!(webrender_api::BorderStyle);
889-
#[cfg(feature = "webrender_api")]
890-
malloc_size_of_is_0!(webrender_api::BoxShadowClipMode);
891-
#[cfg(feature = "webrender_api")]
892-
malloc_size_of_is_0!(webrender_api::ColorF);
893-
#[cfg(feature = "webrender_api")]
894-
malloc_size_of_is_0!(webrender_api::ComplexClipRegion);
895-
#[cfg(feature = "webrender_api")]
896-
malloc_size_of_is_0!(webrender_api::ExtendMode);
897-
#[cfg(feature = "webrender_api")]
898-
malloc_size_of_is_0!(webrender_api::FilterOp);
899-
#[cfg(feature = "webrender_api")]
900-
malloc_size_of_is_0!(webrender_api::ExternalScrollId);
901-
#[cfg(feature = "webrender_api")]
902-
malloc_size_of_is_0!(webrender_api::FontInstanceKey);
903-
#[cfg(feature = "webrender_api")]
904-
malloc_size_of_is_0!(webrender_api::GradientStop);
905-
#[cfg(feature = "webrender_api")]
906-
malloc_size_of_is_0!(webrender_api::GlyphInstance);
907-
#[cfg(feature = "webrender_api")]
908-
malloc_size_of_is_0!(webrender_api::NinePatchBorder);
909-
#[cfg(feature = "webrender_api")]
910-
malloc_size_of_is_0!(webrender_api::ImageKey);
911-
#[cfg(feature = "webrender_api")]
912-
malloc_size_of_is_0!(webrender_api::ImageRendering);
913-
#[cfg(feature = "webrender_api")]
914-
malloc_size_of_is_0!(webrender_api::LineStyle);
915-
#[cfg(feature = "webrender_api")]
916-
malloc_size_of_is_0!(webrender_api::MixBlendMode);
917-
#[cfg(feature = "webrender_api")]
918-
malloc_size_of_is_0!(webrender_api::NormalBorder);
919-
#[cfg(feature = "webrender_api")]
920-
malloc_size_of_is_0!(webrender_api::RepeatMode);
921-
#[cfg(feature = "webrender_api")]
922-
malloc_size_of_is_0!(webrender_api::StickyOffsetBounds);
923-
#[cfg(feature = "webrender_api")]
924-
malloc_size_of_is_0!(webrender_api::TransformStyle);
925-
926-
#[cfg(feature = "servo")]
927-
impl MallocSizeOf for keyboard_types::Key {
928-
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
929-
match self {
930-
keyboard_types::Key::Character(ref s) => s.size_of(ops),
931-
_ => 0,
932-
}
933-
}
934-
}
935-
936-
#[cfg(feature = "servo")]
937-
malloc_size_of_is_0!(keyboard_types::Modifiers);
938-
939-
#[cfg(feature = "servo")]
940-
impl MallocSizeOf for xml5ever::QualName {
941-
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
942-
self.prefix.size_of(ops) + self.ns.size_of(ops) + self.local.size_of(ops)
943-
}
944-
}
945-
946-
#[cfg(feature = "servo")]
947-
malloc_size_of_is_0!(std::time::Duration);
948-
#[cfg(feature = "servo")]
949-
malloc_size_of_is_0!(std::time::SystemTime);
950-
#[cfg(feature = "servo")]
951-
malloc_size_of_is_0!(std::time::Instant);
952-
#[cfg(feature = "servo")]
953-
malloc_size_of_hash_set!(indexmap::IndexSet<T, S>);
954-
#[cfg(feature = "servo")]
955-
malloc_size_of_hash_map!(indexmap::IndexMap<K, V, S>);
956-
#[cfg(feature = "servo")]
957-
malloc_size_of_is_0!(http::StatusCode);
958-
959-
// Placeholder for unique case where internals of Sender cannot be measured.
960-
// malloc size of is 0 macro complains about type supplied!
961-
#[cfg(feature = "servo")]
962-
impl<T> MallocSizeOf for crossbeam_channel::Sender<T> {
963-
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
964-
0
965-
}
966-
}
967-
968-
#[cfg(feature = "servo")]
969-
impl<T> MallocSizeOf for tokio::sync::mpsc::UnboundedSender<T> {
970-
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
971-
0
972-
}
973-
}
974-
975820
/// Measurable that defers to inner value and used to verify MallocSizeOf implementation in a
976821
/// struct.
977822
#[derive(Clone)]
@@ -990,10 +835,3 @@ impl<T: MallocSizeOf> DerefMut for Measurable<T> {
990835
&mut self.0
991836
}
992837
}
993-
994-
#[cfg(feature = "servo")]
995-
impl<T: MallocSizeOf> MallocSizeOf for accountable_refcell::RefCell<T> {
996-
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
997-
self.borrow().size_of(ops)
998-
}
999-
}

‎style/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ thin-vec = "0.2.1"
100100
uluru = "3.0"
101101
unicode-bidi = { version = "0.3", default-features = false }
102102
void = "1.0.2"
103-
url = { version = "2.5", optional = true }
103+
url = { version = "2.5", optional = true, features = ["serde"] }
104104

105105
[build-dependencies]
106106
lazy_static = "1"

0 commit comments

Comments
 (0)
Please sign in to comment.