Skip to content
This repository was archived by the owner on Jul 10, 2023. It is now read-only.

Commit 7913872

Browse files
author
bors-servo
committed
Auto merge of #42 - servo:vecdeque, r=glennw
impl HeapSizeOf for VeqDeque <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.svg" height="40" alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/42) <!-- Reviewable:end -->
2 parents c5b2b9d + 602ca86 commit 7913872

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "heapsize"
3-
version = "0.3.1"
3+
version = "0.3.2"
44
authors = [ "The Servo Project Developers" ]
55
description = "Infrastructure for measuring the total runtime size of an object on the heap"
66
license = "MPL-2.0"

src/lib.rs

+13-5
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
77
use std::borrow::Cow;
88
use std::cell::{Cell, RefCell};
9-
use std::collections::{BTreeMap, HashMap, LinkedList};
9+
use std::collections::{BTreeMap, HashMap, LinkedList, VecDeque};
1010
#[cfg(feature = "unstable")]
1111
use std::hash::BuildHasher;
1212
use std::hash::Hash;
@@ -160,10 +160,18 @@ impl<T: HeapSizeOf + Copy> HeapSizeOf for Cell<T> {
160160

161161
impl<T: HeapSizeOf> HeapSizeOf for Vec<T> {
162162
fn heap_size_of_children(&self) -> usize {
163-
unsafe {
164-
heap_size_of(self.as_ptr() as *const c_void)
165-
+ self.iter().fold(0, |n, elem| n + elem.heap_size_of_children())
166-
}
163+
self.iter().fold(
164+
unsafe { heap_size_of(self.as_ptr() as *const c_void) },
165+
|n, elem| n + elem.heap_size_of_children())
166+
}
167+
}
168+
169+
impl<T: HeapSizeOf> HeapSizeOf for VecDeque<T> {
170+
fn heap_size_of_children(&self) -> usize {
171+
self.iter().fold(
172+
// FIXME: get the buffer pointer for heap_size_of(), capacity() is a lower bound:
173+
self.capacity() * size_of::<T>(),
174+
|n, elem| n + elem.heap_size_of_children())
167175
}
168176
}
169177

0 commit comments

Comments
 (0)