Skip to content

Commit

Permalink
Use Vec<T> for keeping track of gc objects
Browse files Browse the repository at this point in the history
  • Loading branch information
HalidOdat committed Dec 1, 2023
1 parent 9f181ef commit 8330f9d
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 90 deletions.
2 changes: 0 additions & 2 deletions boa_gc/src/internals/ephemeron_box.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const NON_ROOTS_MAX: u32 = NON_ROOTS_MASK;
pub(crate) struct EphemeronBoxHeader {
ref_count: Cell<u32>,
non_root_count: Cell<u32>,
pub(crate) next: Cell<Option<NonNull<dyn ErasedEphemeronBox>>>,
}

impl EphemeronBoxHeader {
Expand All @@ -28,7 +27,6 @@ impl EphemeronBoxHeader {
Self {
ref_count: Cell::new(1),
non_root_count: Cell::new(0),
next: Cell::new(None),
}
}

Expand Down
8 changes: 1 addition & 7 deletions boa_gc/src/internals/gc_box.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
use crate::Trace;
use std::{
cell::Cell,
fmt,
ptr::{self, NonNull},
};
use std::{cell::Cell, fmt, ptr};

const MARK_MASK: u32 = 1 << (u32::BITS - 1);
const NON_ROOTS_MASK: u32 = !MARK_MASK;
Expand All @@ -20,7 +16,6 @@ const NON_ROOTS_MAX: u32 = NON_ROOTS_MASK;
pub(crate) struct GcBoxHeader {
ref_count: Cell<u32>,
non_root_count: Cell<u32>,
pub(crate) next: Cell<Option<NonNull<GcBox<dyn Trace>>>>,
}

impl GcBoxHeader {
Expand All @@ -29,7 +24,6 @@ impl GcBoxHeader {
Self {
ref_count: Cell::new(1),
non_root_count: Cell::new(0),
next: Cell::new(None),
}
}

Expand Down
9 changes: 0 additions & 9 deletions boa_gc/src/internals/weak_map_box.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
use crate::{pointers::RawWeakMap, GcRefCell, Trace, WeakGc};
use std::{cell::Cell, ptr::NonNull};

/// A box that is used to track [`WeakMap`][`crate::WeakMap`]s.
pub(crate) struct WeakMapBox<K: Trace + Sized + 'static, V: Trace + Sized + 'static> {
pub(crate) map: WeakGc<GcRefCell<RawWeakMap<K, V>>>,
pub(crate) next: Cell<Option<NonNull<dyn ErasedWeakMapBox>>>,
}

/// A trait that is used to erase the type of a [`WeakMapBox`].
pub(crate) trait ErasedWeakMapBox {
/// Clear dead entries from the [`WeakMapBox`].
fn clear_dead_entries(&self);

/// A pointer to the next [`WeakMapBox`].
fn next(&self) -> &Cell<Option<NonNull<dyn ErasedWeakMapBox>>>;

/// Returns `true` if the [`WeakMapBox`] is live.
fn is_live(&self) -> bool;

Expand All @@ -31,10 +26,6 @@ impl<K: Trace, V: Trace + Clone> ErasedWeakMapBox for WeakMapBox<K, V> {
}
}

fn next(&self) -> &Cell<Option<NonNull<dyn ErasedWeakMapBox>>> {
&self.next
}

fn is_live(&self) -> bool {
self.map.upgrade().is_some()
}
Expand Down
Loading

0 comments on commit 8330f9d

Please sign in to comment.