From ca0fdf600d4534a7f34db7e9317621f1faa80f0d Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Sat, 8 Aug 2015 21:16:47 -0700 Subject: [PATCH 1/4] Add HeapSizeOf support. --- Cargo.toml | 6 +++++- src/lib.rs | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index d2725565..58a509b9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,10 +22,14 @@ optional = true [dependencies.serde_macros] optional = true +[dependencies.heapsize] +git = "https://github.com/servo/heapsize.git" +optional = true + [dependencies] encoding = "0.2" matches = "0.1" [features] serde-serialization = [ "serde", "serde_macros" ] - +heap_size = [ "heapsize" ] diff --git a/src/lib.rs b/src/lib.rs index e63f38bd..ffadf870 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,6 +71,7 @@ extern crate encoding; #[cfg(test)] extern crate tempdir; #[cfg(test)] extern crate rustc_serialize; #[cfg(feature = "serde-serialization")] extern crate serde; +#[cfg(feature = "heap_size")] #[macro_use] extern crate heapsize; pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation}; pub use rules_and_declarations::{parse_important}; @@ -83,6 +84,8 @@ pub use nth::parse_nth; pub use serializer::{ToCss, CssStringWriter, serialize_identifier, serialize_string}; pub use parser::{Parser, Delimiter, Delimiters, SourcePosition}; +#[cfg(feature = "heap_size")] known_heap_size!(0, Color, RGBA); + /** From 19a5f6dbcede9f007ab12f13aac09423855b07cc Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 11 Aug 2015 09:29:54 -0700 Subject: [PATCH 2/4] Build on Travis. --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 532be9d6..8d9c527f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,6 +9,7 @@ script: - cargo build --verbose - cargo test --verbose - cargo doc --verbose + - ([ $TRAVIS_RUST_VERSION != nightly ] || cargo test --features heap_size) after_success: | [ $TRAVIS_RUST_VERSION = nightly ] && From bc905f4bab853faeedafc93887576feca31db484 Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 11 Aug 2015 09:34:31 -0700 Subject: [PATCH 3/4] Use crates.io heapsize. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 58a509b9..b1c39ef6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,7 +23,7 @@ optional = true optional = true [dependencies.heapsize] -git = "https://github.com/servo/heapsize.git" +version = "0.1.1" optional = true [dependencies] From 9e84a9f38a08801c00a62a840505590cc7ad914f Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Tue, 11 Aug 2015 09:39:18 -0700 Subject: [PATCH 4/4] Use `heapsize_plugin` instead of the macro. --- Cargo.toml | 6 +++++- src/color.rs | 2 ++ src/lib.rs | 7 ++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b1c39ef6..da6848ab 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,10 +26,14 @@ optional = true version = "0.1.1" optional = true +[dependencies.heapsize_plugin] +version = "0.0.1" +optional = true + [dependencies] encoding = "0.2" matches = "0.1" [features] serde-serialization = [ "serde", "serde_macros" ] -heap_size = [ "heapsize" ] +heap_size = [ "heapsize", "heapsize_plugin" ] diff --git a/src/color.rs b/src/color.rs index 31debed9..c91b5b7b 100644 --- a/src/color.rs +++ b/src/color.rs @@ -11,6 +11,7 @@ use super::{Token, Parser, ToCss}; /// A color with red, green, blue, and alpha components. #[derive(Clone, Copy, PartialEq, Debug)] #[cfg_attr(feature = "serde-serialization", derive(Deserialize, Serialize))] +#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub struct RGBA { /// The red channel. Nominally in 0.0 ... 1.0. pub red: f32, @@ -41,6 +42,7 @@ impl ToCss for RGBA { /// A value. #[derive(Clone, Copy, PartialEq, Debug)] +#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))] pub enum Color { /// The 'currentColor' keyword CurrentColor, diff --git a/src/lib.rs b/src/lib.rs index ffadf870..cb0459e4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,6 +9,9 @@ #![cfg_attr(feature = "serde-serialization", feature(custom_derive))] #![cfg_attr(feature = "serde-serialization", feature(plugin))] #![cfg_attr(feature = "serde-serialization", plugin(serde_macros))] +#![cfg_attr(feature = "heap_size", feature(custom_derive))] +#![cfg_attr(feature = "heap_size", feature(plugin))] +#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))] /*! @@ -71,7 +74,7 @@ extern crate encoding; #[cfg(test)] extern crate tempdir; #[cfg(test)] extern crate rustc_serialize; #[cfg(feature = "serde-serialization")] extern crate serde; -#[cfg(feature = "heap_size")] #[macro_use] extern crate heapsize; +#[cfg(feature = "heap_size")] extern crate heapsize; pub use tokenizer::{Token, NumericValue, PercentageValue, SourceLocation}; pub use rules_and_declarations::{parse_important}; @@ -84,8 +87,6 @@ pub use nth::parse_nth; pub use serializer::{ToCss, CssStringWriter, serialize_identifier, serialize_string}; pub use parser::{Parser, Delimiter, Delimiters, SourcePosition}; -#[cfg(feature = "heap_size")] known_heap_size!(0, Color, RGBA); - /**