From 024d84192727b3c5bfbc40247559ce9af4d92d5d Mon Sep 17 00:00:00 2001 From: Haled Odat Date: Thu, 30 Mar 2023 00:27:55 +0200 Subject: [PATCH] Implement Trace and Finalize on ThinVec --- Cargo.lock | 1 + boa_engine/Cargo.toml | 2 +- boa_engine/src/object/property_map.rs | 15 +-------------- boa_gc/Cargo.toml | 6 ++++++ boa_gc/src/trace.rs | 13 +++++++++++++ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 7a5664ecc33..9d39c523fc0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -398,6 +398,7 @@ version = "0.16.0" dependencies = [ "boa_macros", "boa_profiler", + "thin-vec", ] [[package]] diff --git a/boa_engine/Cargo.toml b/boa_engine/Cargo.toml index aca72c6d911..93bffb2da8c 100644 --- a/boa_engine/Cargo.toml +++ b/boa_engine/Cargo.toml @@ -41,7 +41,7 @@ console = [] [dependencies] boa_interner.workspace = true -boa_gc.workspace = true +boa_gc = { workspace = true, features = [ "thinvec" ] } boa_profiler.workspace = true boa_macros.workspace = true boa_ast.workspace = true diff --git a/boa_engine/src/object/property_map.rs b/boa_engine/src/object/property_map.rs index 32eb5ca475e..d9923f8ef19 100644 --- a/boa_engine/src/object/property_map.rs +++ b/boa_engine/src/object/property_map.rs @@ -36,7 +36,7 @@ unsafe impl Trace for OrderedHashMap { /// - `Sparse` Storage /// /// By default it is dense storage. -#[derive(Debug, Finalize)] +#[derive(Debug, Trace, Finalize)] enum IndexedProperties { /// Dense storage holds a contiguous array of properties where the index in the array is the key of the property. /// These are known to be data descriptors with a value field, writable field set to `true`, configurable field set to `true`, enumerable field set to `true`. @@ -55,19 +55,6 @@ enum IndexedProperties { Sparse(Box>), } -unsafe impl Trace for IndexedProperties { - custom_trace!(this, { - match this { - Self::Dense(vec) => { - for elem in vec.iter() { - mark(elem); - } - } - Self::Sparse(map) => mark(map), - } - }); -} - impl Default for IndexedProperties { #[inline] fn default() -> Self { diff --git a/boa_gc/Cargo.toml b/boa_gc/Cargo.toml index 39f1afa64c1..74565960e09 100644 --- a/boa_gc/Cargo.toml +++ b/boa_gc/Cargo.toml @@ -10,6 +10,12 @@ license.workspace = true repository.workspace = true rust-version.workspace = true +[features] +# Enable default implementatio of trace and finalize thin-vec crate +thinvec = ["thin-vec"] + [dependencies] boa_profiler.workspace = true boa_macros.workspace = true + +thin-vec = { version = "0.2.12", optional = true } \ No newline at end of file diff --git a/boa_gc/src/trace.rs b/boa_gc/src/trace.rs index f839ba7b79f..464cd989d66 100644 --- a/boa_gc/src/trace.rs +++ b/boa_gc/src/trace.rs @@ -308,6 +308,19 @@ unsafe impl Trace for Vec { }); } +#[cfg(feature = "thin-vec")] +impl Finalize for thin_vec::ThinVec {} + +#[cfg(feature = "thin-vec")] +// SAFETY: All the inner elements of the `Vec` are correctly marked. +unsafe impl Trace for thin_vec::ThinVec { + custom_trace!(this, { + for e in this { + mark(e); + } + }); +} + impl Finalize for Option {} // SAFETY: The inner value of the `Option` is correctly marked. unsafe impl Trace for Option {