style: Remove ThinBoxedSlice

The only remaining consumers are ::-moz-tree pseudo-elements (we used to
use ThinBoxedSlice for other data structures in the past).

Those are not particularly performance sensitive so I think just
double-boxing is fine. In the future, if we wanted to avoid the double
indirection, we could probably use the "thin" crate
(https://docs.rs/thin) or similar, which stores the length of the slice
along with the allocation, making the pointer thin in all
configurations, much like "ThinArc" does:

  https://searchfox.org/mozilla-central/rev/1ce2eea39442190a71a1f8f650d098f286bf4a01/servo/components/servo_arc/lib.rs#891

In practice though, I don't think it's particularly worth it for this
specific case.

Differential Revision: https://phabricator.services.mozilla.com/D134672
This commit is contained in:
Emilio Cobos Álvarez 2023-06-06 23:25:18 +02:00 committed by Oriol Brufau
parent fc4d185079
commit 5b62f66f6e
7 changed files with 5 additions and 43 deletions

View file

@ -44,7 +44,6 @@ servo_arc = { path = "../servo_arc" }
smallbitvec = { workspace = true }
smallvec = { workspace = true }
string_cache = { workspace = true, optional = true }
thin-slice = { workspace = true }
time = { workspace = true, optional = true }
tokio = { workspace = true }
url = { workspace = true, optional = true }

View file

@ -213,24 +213,6 @@ impl<T: MallocSizeOf + ?Sized> MallocSizeOf for Box<T> {
}
}
impl<T> MallocShallowSizeOf for thin_slice::ThinBoxedSlice<T> {
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
let mut n = 0;
unsafe {
n += thin_slice::ThinBoxedSlice::spilled_storage(self)
.map_or(0, |ptr| ops.malloc_size_of(ptr));
n += ops.malloc_size_of(&**self);
}
n
}
}
impl<T: MallocSizeOf> MallocSizeOf for thin_slice::ThinBoxedSlice<T> {
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.shallow_size_of(ops) + (**self).size_of(ops)
}
}
impl MallocSizeOf for () {
fn size_of(&self, _ops: &mut MallocSizeOfOps) -> usize {
0

View file

@ -17,8 +17,7 @@ path = "lib.rs"
doctest = false
[features]
gecko = ["style_traits/gecko", "bindgen", "regex", "toml",
"num_cpus", "thin-slice"]
gecko = ["style_traits/gecko", "bindgen", "regex", "toml", "num_cpus"]
servo = ["serde", "style_traits/servo", "servo_atoms", "servo_config", "html5ever",
"cssparser/serde", "encoding_rs", "malloc_size_of/servo", "servo_url",
"string_cache", "to_shmem/servo",
@ -68,7 +67,6 @@ smallvec = "1.0"
string_cache = { version = "0.8", optional = true }
style_derive = { path = "../style_derive" }
style_traits = { path = "../style_traits" }
thin-slice = { version = "0.1.0", optional = true }
time = "0.1"
to_shmem = { path = "../to_shmem" }
to_shmem_derive = { path = "../to_shmem_derive" }

View file

@ -17,7 +17,6 @@ use crate::string_cache::Atom;
use crate::values::serialize_atom_identifier;
use cssparser::ToCss;
use std::fmt;
use thin_slice::ThinBoxedSlice;
include!(concat!(
env!("OUT_DIR"),

View file

@ -3,12 +3,15 @@
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/// Gecko's pseudo-element definition.
///
/// We intentionally double-box legacy ::-moz-tree pseudo-elements to keep the
/// size of PseudoElement (and thus selector components) small.
#[derive(Clone, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToShmem)]
pub enum PseudoElement {
% for pseudo in PSEUDOS:
/// ${pseudo.value}
% if pseudo.is_tree_pseudo_element():
${pseudo.capitalized_pseudo()}(ThinBoxedSlice<Atom>),
${pseudo.capitalized_pseudo()}(Box<Box<[Atom]>>),
% else:
${pseudo.capitalized_pseudo()},
% endif

View file

@ -20,4 +20,3 @@ servo_arc = { path = "../servo_arc" }
smallbitvec = { workspace = true }
smallvec = { workspace = true }
string_cache = { workspace = true, optional = true }
thin-slice = { workspace = true }

View file

@ -32,7 +32,6 @@ use std::os::raw::c_void;
use std::ptr::{self, NonNull};
use std::slice;
use std::str;
use thin_slice::ThinBoxedSlice;
/// Result type for ToShmem::to_shmem.
///
@ -334,23 +333,6 @@ impl<T: ToShmem> ToShmem for Box<[T]> {
}
}
impl<T: ToShmem> ToShmem for ThinBoxedSlice<T> {
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> Result<Self> {
// We could support this if we needed but in practice we will never
// need to handle such big ThinBoxedSlices.
assert!(
self.spilled_storage().is_none(),
"ToShmem failed for ThinBoxedSlice: too many entries ({})",
self.len(),
);
unsafe {
let dest = to_shmem_slice(self.iter(), builder)?;
Ok(ManuallyDrop::new(ThinBoxedSlice::from_raw(dest)))
}
}
}
impl ToShmem for Box<str> {
fn to_shmem(&self, builder: &mut SharedMemoryBuilder) -> Result<Self> {
// Reserve space for the string bytes.