Skip to content

Commit

Permalink
Implement Trace and Finalize on ThinVec
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Mar 30, 2023
1 parent 159073a commit b5ac5af
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 15 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion boa_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
15 changes: 1 addition & 14 deletions boa_engine/src/object/property_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ unsafe impl<K: Trace> Trace for OrderedHashMap<K> {
/// - `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`.
Expand All @@ -55,19 +55,6 @@ enum IndexedProperties {
Sparse(Box<FxHashMap<u32, PropertyDescriptor>>),
}

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 {
Expand Down
6 changes: 6 additions & 0 deletions boa_gc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
13 changes: 13 additions & 0 deletions boa_gc/src/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,19 @@ unsafe impl<T: Trace> Trace for Vec<T> {
});
}

#[cfg(feature = "thin-vec")]
impl<T: Trace> Finalize for thin_vec::ThinVec<T> {}

#[cfg(feature = "thin-vec")]
// SAFETY: All the inner elements of the `Vec` are correctly marked.
unsafe impl<T: Trace> Trace for thin_vec::ThinVec<T> {
custom_trace!(this, {
for e in this {
mark(e);
}
});
}

impl<T: Trace> Finalize for Option<T> {}
// SAFETY: The inner value of the `Option` is correctly marked.
unsafe impl<T: Trace> Trace for Option<T> {
Expand Down

0 comments on commit b5ac5af

Please sign in to comment.