Skip to content

Commit 4bfbc42

Browse files
author
bors-servo
committed
Auto merge of #99 - notriddle:master, r=jdm
Add `HeapSizeOf` implementation. Part of servo/heapsize#5. <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/euclid/99) <!-- Reviewable:end -->
2 parents cbd1602 + 850f8a5 commit 4bfbc42

10 files changed

+34
-0
lines changed

Cargo.toml

+12
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,22 @@ documentation = "http://doc.servo.org/euclid/"
77
repository = "https://github.com/servo/euclid"
88
license = "MIT / Apache-2.0"
99

10+
[features]
11+
heap_size = [ "heapsize", "heapsize_plugin" ]
12+
1013
[dependencies]
1114
rustc-serialize = "0.3.2"
1215
rand = "0.3.7"
1316
num = "0.1.24"
1417
log = "0.3.1"
1518
serde = "*"
1619
serde_macros = "*"
20+
21+
[dependencies.heapsize]
22+
version = "0.1.2"
23+
optional = true
24+
25+
[dependencies.heapsize_plugin]
26+
version = "0.0.1"
27+
optional = true
28+

src/length.rs

+3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,10 @@ use std::marker::PhantomData;
2828
///
2929
/// You can multiply a Length by a `scale_factor::ScaleFactor` to convert it from one unit to
3030
/// another. See the ScaleFactor docs for an example.
31+
// Uncomment the derive, and remove the macro call, once heapsize gets
32+
// PhantomData<T> support.
3133
#[derive(Copy, RustcDecodable, RustcEncodable, Debug)]
34+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
3235
pub struct Length<Unit, T>(pub T, PhantomData<Unit>);
3336

3437
impl<Unit,T> Deserialize for Length<Unit,T> where T: Deserialize {

src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
#![plugin(serde_macros)]
1313

14+
#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]
15+
16+
#[cfg(feature = "heap_size")]
17+
#[macro_use]
18+
extern crate heapsize;
19+
1420
#[macro_use]
1521
extern crate log;
1622
extern crate rustc_serialize;

src/matrix.rs

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use point::{Point2D, Point4D};
1212

1313

1414
#[derive(Debug, Copy, Clone, PartialEq, Deserialize, Serialize)]
15+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
1516
pub struct Matrix4 {
1617
pub m11: f32, pub m12: f32, pub m13: f32, pub m14: f32,
1718
pub m21: f32, pub m22: f32, pub m23: f32, pub m24: f32,

src/matrix2d.rs

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use size::Size2D;
1414
use std::ops::{Add, Mul, Sub};
1515

1616
#[derive(Clone, Copy, Deserialize, Serialize)]
17+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
1718
pub struct Matrix2D<T> {
1819
m11: T, m12: T,
1920
m21: T, m22: T,

src/point.rs

+3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::fmt::{self, Formatter};
1616
use std::ops::{Add, Neg, Mul, Sub, Div};
1717

1818
#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq, Deserialize, Serialize)]
19+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
1920
pub struct Point2D<T> {
2021
pub x: T,
2122
pub y: T
@@ -139,6 +140,7 @@ impl<Unit, T: NumCast + Clone> Point2D<Length<Unit, T>> {
139140
}
140141

141142
#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq)]
143+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
142144
pub struct Point3D<T> {
143145
pub x: T,
144146
pub y: T,
@@ -198,6 +200,7 @@ impl <T:Clone + Neg<Output=T>> Neg for Point3D<T> {
198200
}
199201

200202
#[derive(Clone, Copy, RustcDecodable, RustcEncodable, Eq, Hash, PartialEq)]
203+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
201204
pub struct Point4D<T> {
202205
pub x: T,
203206
pub y: T,

src/rect.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use std::fmt::{self, Formatter};
1818
use std::ops::{Add, Sub, Mul, Div};
1919

2020
#[derive(Clone, Copy, RustcDecodable, RustcEncodable, PartialEq, Deserialize, Serialize)]
21+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
2122
pub struct Rect<T> {
2223
pub origin: Point2D<T>,
2324
pub size: Size2D<T>,

src/scale_factor.rs

+4
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ use std::marker::PhantomData;
3434
/// let one_foot: Length<Inch, f32> = Length::new(12.0);
3535
/// let one_foot_in_mm: Length<Mm, f32> = one_foot * mm_per_inch;
3636
/// ```
37+
// Uncomment the derive, and remove the macro call, once heapsize gets
38+
// PhantomData<T> support.
3739
#[derive(Copy, RustcDecodable, RustcEncodable, Debug)]
40+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
3841
pub struct ScaleFactor<Src, Dst, T>(pub T, PhantomData<(Src, Dst)>);
3942

43+
4044
impl<Src,Dst,T> Deserialize for ScaleFactor<Src,Dst,T> where T: Deserialize {
4145
fn deserialize<D>(deserializer: &mut D) -> Result<ScaleFactor<Src,Dst,T>,D::Error>
4246
where D: Deserializer {

src/side_offsets.rs

+2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ use std::ops::Add;
1616
/// A group of side offsets, which correspond to top/left/bottom/right for borders, padding,
1717
/// and margins in CSS.
1818
#[derive(Clone, Copy, PartialEq, Debug, Deserialize, Serialize)]
19+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
1920
pub struct SideOffsets2D<T> {
2021
pub top: T,
2122
pub right: T,
@@ -76,6 +77,7 @@ impl<T: Zero> SideOffsets2D<T> {
7677
/// A SIMD enabled version of SideOffsets2D specialized for i32.
7778
#[derive(Clone, Copy, PartialEq)]
7879
#[simd]
80+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
7981
pub struct SideOffsets2DSimdI32 {
8082
pub top: i32,
8183
pub bottom: i32,

src/size.rs

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use std::fmt::{self, Formatter};
1515
use std::ops::{Mul, Div};
1616

1717
#[derive(Clone, Copy, RustcDecodable, RustcEncodable, PartialEq, Deserialize, Serialize)]
18+
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
1819
pub struct Size2D<T> {
1920
pub width: T,
2021
pub height: T

0 commit comments

Comments
 (0)