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

impl HeapSizeOf for VeqDeque #42

Merged
merged 1 commit into from
Feb 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "heapsize"
version = "0.3.1"
version = "0.3.2"
authors = [ "The Servo Project Developers" ]
description = "Infrastructure for measuring the total runtime size of an object on the heap"
license = "MPL-2.0"
Expand Down
18 changes: 13 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use std::borrow::Cow;
use std::cell::{Cell, RefCell};
use std::collections::{BTreeMap, HashMap, LinkedList};
use std::collections::{BTreeMap, HashMap, LinkedList, VecDeque};
#[cfg(feature = "unstable")]
use std::hash::BuildHasher;
use std::hash::Hash;
Expand Down Expand Up @@ -160,10 +160,18 @@ impl<T: HeapSizeOf + Copy> HeapSizeOf for Cell<T> {

impl<T: HeapSizeOf> HeapSizeOf for Vec<T> {
fn heap_size_of_children(&self) -> usize {
unsafe {
heap_size_of(self.as_ptr() as *const c_void)
+ self.iter().fold(0, |n, elem| n + elem.heap_size_of_children())
}
self.iter().fold(
unsafe { heap_size_of(self.as_ptr() as *const c_void) },
|n, elem| n + elem.heap_size_of_children())
}
}

impl<T: HeapSizeOf> HeapSizeOf for VecDeque<T> {
fn heap_size_of_children(&self) -> usize {
self.iter().fold(
// FIXME: get the buffer pointer for heap_size_of(), capacity() is a lower bound:
self.capacity() * size_of::<T>(),
|n, elem| n + elem.heap_size_of_children())
}
}

Expand Down