Skip to content

Commit b17ba46

Browse files
authored
Merge pull request #30 from servo/malloc_size_of
Implement MallocSizeOf for smallbitvec
2 parents 2d1780f + e4341ad commit b17ba46

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed

Cargo.lock

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "smallbitvec"
3-
version = "2.5.3"
3+
version = "2.5.4"
44
authors = ["Matt Brubeck <mbrubeck@limpet.net>"]
55
license = "MIT OR Apache-2.0"
66
description = "A bit vector optimized for size and inline storage"
@@ -12,6 +12,9 @@ readme = "README.md"
1212
edition = "2021"
1313
rust-version = "1.56"
1414

15+
[dependencies]
16+
malloc_size_of = { version = "0.1", default-features = false, optional = true }
17+
1518
[dev-dependencies]
1619
rand = { version = "0.8.5", features = ["small_rng"] }
1720
bit-vec = "0.6.3"

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -865,6 +865,17 @@ impl Index<usize> for SmallBitVec {
865865
}
866866
}
867867

868+
#[cfg(feature = "malloc_size_of")]
869+
impl malloc_size_of::MallocSizeOf for SmallBitVec {
870+
fn size_of(&self, ops: &mut malloc_size_of::MallocSizeOfOps) -> usize {
871+
if let Some(ptr) = self.heap_ptr() {
872+
unsafe { ops.malloc_size_of(ptr) }
873+
} else {
874+
0
875+
}
876+
}
877+
}
878+
868879
impl hash::Hash for SmallBitVec {
869880
#[inline]
870881
fn hash<H: hash::Hasher>(&self, state: &mut H) {

0 commit comments

Comments
 (0)