Skip to content

Commit 3497b30

Browse files
committed
Add featureflag for heapsizeof
1 parent 6f87ab5 commit 3497b30

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ rust:
55
- stable
66
script: |
77
cargo build --verbose &&
8+
cargo build --features=heapsizeof --verbose &&
89
cargo test --verbose &&
10+
cargo test --features=heapsizeof --verbose &&
911
([ $TRAVIS_RUST_VERSION != nightly ] || cargo bench --verbose bench)
1012
notifications:
1113
webhooks: http://build.servo.org:54856/travis

Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,12 @@ keywords = ["small", "vec", "vector", "stack"]
99
readme = "README.md"
1010
documentation = "http://doc.servo.org/smallvec/"
1111

12+
[features]
13+
heapsizeof = ["heapsize"]
14+
1215
[lib]
1316
name = "smallvec"
1417
path = "lib.rs"
1518

1619
[dependencies]
17-
heapsize = "0.3"
20+
heapsize = { version = "0.3", optional = true }

lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
//! to the heap for larger allocations. This can be a useful optimization for improving cache
77
//! locality and reducing allocator traffic for workloads that fit within the inline buffer.
88
9+
#![feature(specialization)]
10+
11+
#[cfg(feature="heapsizeof")]
912
extern crate heapsize;
1013

1114
use std::borrow::{Borrow, BorrowMut};
@@ -14,11 +17,13 @@ use std::fmt;
1417
use std::hash::{Hash, Hasher};
1518
use std::iter::{IntoIterator, FromIterator};
1619
use std::mem;
17-
use std::os::raw::c_void;
1820
use std::ops;
1921
use std::ptr;
2022
use std::slice;
23+
#[cfg(feature="heapsizeof")]
24+
use std::os::raw::c_void;
2125

26+
#[cfg(feature="heapsizeof")]
2227
use heapsize::{HeapSizeOf, heap_size_of};
2328
use SmallVecData::{Inline, Heap};
2429

@@ -510,6 +515,7 @@ impl<A: Array> SmallVec<A> where A::Item: Copy {
510515
}
511516
}
512517

518+
#[cfg(feature="heapsizeof")]
513519
impl<A: Array> HeapSizeOf for SmallVec<A> where A::Item: HeapSizeOf {
514520
fn heap_size_of_children(&self) -> usize {
515521
match self.data {
@@ -853,9 +859,12 @@ impl_array!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 20, 24, 32, 3
853859
#[cfg(test)]
854860
pub mod tests {
855861
use SmallVec;
856-
use heapsize::HeapSizeOf;
857862
use std::borrow::ToOwned;
858863
use std::iter::FromIterator;
864+
865+
#[cfg(feature="heapsizeof")]
866+
use heapsize::HeapSizeOf;
867+
#[cfg(feature="heapsizeof")]
859868
use std::mem::size_of;
860869

861870
// We heap allocate all these strings so that double frees will show up under valgrind.
@@ -1279,6 +1288,7 @@ pub mod tests {
12791288
assert_eq!(&SmallVec::<[u32; 2]>::from_slice(&[1, 2, 3][..])[..], [1, 2, 3]);
12801289
}
12811290

1291+
#[cfg(feature="heapsizeof")]
12821292
#[test]
12831293
fn test_heap_size_of_children() {
12841294
let mut vec = SmallVec::<[u32; 2]>::new();

0 commit comments

Comments
 (0)