Skip to content

Commit b24a541

Browse files
committed
Implement MallocSizeOf for Atom
Signed-off-by: Nico Burns <[email protected]>
1 parent 14ae86a commit b24a541

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ jobs:
3636
run: |
3737
cargo build --no-default-features
3838
cargo build
39+
cargo build --features malloc_size_of
3940
- uses: actions-rs/cargo@v1
4041
with:
4142
command: test

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "string_cache"
3-
version = "0.8.8" # Also update README.md when making a semver-breaking change
3+
version = "0.8.9" # Also update README.md when making a semver-breaking change
44
authors = ["The Servo Project Developers"]
55
description = "A string interning library for Rust, developed as part of the Servo project."
66
license = "MIT OR Apache-2.0"
@@ -25,6 +25,7 @@ default = ["serde_support"]
2525
[dependencies]
2626
precomputed-hash = "0.1"
2727
serde = { version = "1", optional = true }
28+
malloc_size_of = { version = "0.1", default-features = false, optional = true }
2829
phf_shared = "0.11"
2930
new_debug_unreachable = "1.0.2"
3031
parking_lot = "0.12"

src/atom.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,15 @@ pub struct Atom<Static> {
8282
phantom: PhantomData<Static>,
8383
}
8484

85+
// This isn't really correct as the Atoms can technically take up space. But I guess it's ok
86+
// as it is possible to measure the size of the atom set separately/
87+
#[cfg(feature = "malloc_size_of")]
88+
impl<Static: StaticAtomSet> malloc_size_of::MallocSizeOf for Atom<Static> {
89+
fn size_of(&self, _ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
90+
0
91+
}
92+
}
93+
8594
// FIXME: bound removed from the struct definition before of this error for pack_static:
8695
// "error[E0723]: trait bounds other than `Sized` on const fn parameters are unstable"
8796
// https://github.com/rust-lang/rust/issues/57563

0 commit comments

Comments
 (0)