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

Commit

Permalink
Accommodate change of empty vector representation in nightly libstd.
Browse files Browse the repository at this point in the history
  • Loading branch information
jdm committed May 17, 2017
1 parent 5f2f5b7 commit 1f121a2
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 1f121a2

Please sign in to comment.