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

Commit

Permalink
Auto merge of #81 - servo:emptyvec, r=nox
Browse files Browse the repository at this point in the history
Accommodate change of empty vector representation in nightly libstd.

<!-- Reviewable:start -->
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/heapsize/81)
<!-- Reviewable:end -->
  • Loading branch information
bors-servo authored May 18, 2017
2 parents 5f2f5b7 + cd5f46e commit 2cbc81c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
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.9"
version = "0.4.0"
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
14 changes: 7 additions & 7 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::collections::{BTreeMap, HashSet, HashMap, LinkedList, VecDeque};
use std::hash::BuildHasher;
use std::hash::Hash;
use std::marker::PhantomData;
use std::mem::size_of;
use std::mem::{size_of, align_of};
use std::net::{Ipv4Addr, Ipv6Addr};
use std::os::raw::c_void;
use std::sync::Arc;
Expand All @@ -29,11 +29,11 @@ use std::rc::Rc;
/// `unsafe` because the caller must ensure that the pointer is from jemalloc.
/// FIXME: This probably interacts badly with custom allocators:
/// https://doc.rust-lang.org/book/custom-allocators.html
pub unsafe fn heap_size_of(ptr: *const c_void) -> usize {
if ptr == 0x01 as *const c_void {
pub unsafe fn heap_size_of<T>(ptr: *const T) -> usize {
if ptr as usize <= align_of::<T>() {
0
} else {
heap_size_of_impl(ptr)
heap_size_of_impl(ptr as *const c_void)
}
}

Expand Down Expand Up @@ -105,7 +105,7 @@ impl<T: HeapSizeOf> HeapSizeOf for [T] {
impl HeapSizeOf for String {
fn heap_size_of_children(&self) -> usize {
unsafe {
heap_size_of(self.as_ptr() as *const c_void)
heap_size_of(self.as_ptr())
}
}
}
Expand Down Expand Up @@ -231,7 +231,7 @@ impl<T: HeapSizeOf + Copy> HeapSizeOf for Cell<T> {
impl<T: HeapSizeOf> HeapSizeOf for Vec<T> {
fn heap_size_of_children(&self) -> usize {
self.iter().fold(
unsafe { heap_size_of(self.as_ptr() as *const c_void) },
unsafe { heap_size_of(self.as_ptr()) },
|n, elem| n + elem.heap_size_of_children())
}
}
Expand All @@ -250,7 +250,7 @@ impl<T> HeapSizeOf for Vec<Rc<T>> {
// The fate of measuring Rc<T> is still undecided, but we still want to measure
// the space used for storing them.
unsafe {
heap_size_of(self.as_ptr() as *const c_void)
heap_size_of(self.as_ptr())
}
}
}
Expand Down

0 comments on commit 2cbc81c

Please sign in to comment.