Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Merged by Bors] - Remove string-interner dependency and implement custom string Interner #2147

Closed
wants to merge 9 commits into from
Prev Previous commit
Next Next commit
Fix small doc mistakes
  • Loading branch information
jedel1043 committed Jun 30, 2022
commit f37c6dca69f993ba7c93c35eaf7edce2c1690c3d
8 changes: 4 additions & 4 deletions boa_interner/src/interned_str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ impl InternedStr {
/// could cause Undefined Behaviour.
#[inline]
pub(super) unsafe fn as_str(&self) -> &str {
// SAFETY: The user must verify the invariants
// SAFETY: The caller must verify the invariants
// specified on the struct definition.
unsafe { self.ptr.as_ref() }
}
}

impl std::hash::Hash for InternedStr {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
// SAFETY: The user must verify the invariants
// SAFETY: The caller must verify the invariants
// specified in the struct definition.
unsafe {
self.as_str().hash(state);
Expand All @@ -55,15 +55,15 @@ impl Eq for InternedStr {}

impl PartialEq for InternedStr {
fn eq(&self, other: &Self) -> bool {
// SAFETY: The user must verify the invariants
// SAFETY: The caller must verify the invariants
// specified in the struct definition.
unsafe { self.as_str() == other.as_str() }
}
}

impl Borrow<str> for InternedStr {
fn borrow(&self) -> &str {
// SAFETY: The user must verify the invariants
// SAFETY: The caller must verify the invariants
// specified in the struct definition.
unsafe { self.as_str() }
}
Expand Down
5 changes: 2 additions & 3 deletions boa_interner/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,9 @@ impl Interner {
/// memory inside `head` and that it won't be invalidated
/// by allocations and deallocations.
unsafe fn generate_symbol(&mut self, string: NonNull<str>) -> Sym {
// SAFETY: a static `str` lives throughout the entirety of the
// program, so an `InternedStr` pointing to it
// is always safe to use.
let next = Sym::new(self.len() + 1).expect("Adding one makes `self.len()` always `> 0`");
jedel1043 marked this conversation as resolved.
Show resolved Hide resolved
// SAFETY: The caller has to maintain the invariants specified
// on the function.
unsafe {
let interned = InternedStr::new(string);
self.spans.push(interned.clone());
Expand Down
2 changes: 1 addition & 1 deletion boa_interner/src/sym.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ impl Sym {
pub(super) const unsafe fn new_unchecked(value: usize) -> Self {
Self {
value:
// SAFETY: The user must ensure the invariants of the function.
// SAFETY: The caller must ensure the invariants of the function.
unsafe {
NonZeroUsize::new_unchecked(value)
},
Expand Down