Skip to content

Commit

Permalink
add test confirming that ArcIntern<str> is the size of usize
Browse files Browse the repository at this point in the history
  • Loading branch information
droundy committed Apr 11, 2024
1 parent 7e7daa5 commit 75c63d9
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion benches/get_container.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! This is a benchmark to demonstrate that cached types (`String`, `str` as of now)
//! are faster than non-cached types because the lack of getting container from a dashmap.
//!
//!
//! The results show a whopping 26% performance gain for short `ArcIntern<String>`.

use criterion::*;
Expand Down
9 changes: 9 additions & 0 deletions src/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,15 @@ fn arc_has_niche() {
std::mem::size_of::<Option<ArcIntern<String>>>(),
std::mem::size_of::<usize>(),
);

assert_eq!(
std::mem::size_of::<ArcIntern<str>>(),
std::mem::size_of::<usize>(),
);
assert_eq!(
std::mem::size_of::<Option<ArcIntern<str>>>(),
std::mem::size_of::<usize>(),
);
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions src/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,10 +323,10 @@ impl<'a, T: ?Sized> ArenaIntern<'a, T> {
/// struct Bar {
/// baz: String,
/// }
///
///
/// struct Foo<'a>(ArenaIntern<'a, Bar>);
/// ```
///
///
/// The following code does not compile.
/// ```compile_fail
/// # use internment::ArenaIntern;
Expand Down

0 comments on commit 75c63d9

Please sign in to comment.