diff --git a/Cargo.toml b/Cargo.toml index b97d38eeb..21eedbd15 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,12 +27,11 @@ rustc-serialize = "0.3" [features] query_encoding = ["encoding"] -heap_size = ["heapsize", "heapsize_plugin"] +heap_size = ["heapsize"] [dependencies] encoding = {version = "0.2", optional = true} heapsize = {version = ">=0.1.1, <0.4", optional = true} -heapsize_plugin = {version = "0.1.0", optional = true} idna = { version = "0.1.0", path = "./idna" } matches = "0.1" rustc-serialize = {version = "0.3", optional = true} diff --git a/Makefile b/Makefile index a80d8a5f5..7441b6649 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ test: cargo test --features "query_encoding serde rustc-serialize" - [ x$$TRAVIS_RUST_VERSION != xnightly ] || cargo test --features heap_size + [ x$$TRAVIS_RUST_VERSION != xnightly ] || cargo test --features heapsize doc: cargo doc --features "query_encoding serde rustc-serialize" diff --git a/src/host.rs b/src/host.rs index 11950a6fc..47b049a27 100644 --- a/src/host.rs +++ b/src/host.rs @@ -6,6 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf; use std::cmp; use std::fmt::{self, Formatter}; use std::io; @@ -16,7 +17,6 @@ use percent_encoding::percent_decode; use idna; #[derive(Copy, Clone, Debug, Eq, PartialEq)] -#[cfg_attr(feature="heap_size", derive(HeapSizeOf))] pub enum HostInternal { None, Domain, @@ -24,6 +24,9 @@ pub enum HostInternal { Ipv6(Ipv6Addr), } +#[cfg(feature = "heapsize")] +known_heap_size!(0, HostInternal); + impl From> for HostInternal { fn from(host: Host) -> HostInternal { match host { @@ -36,7 +39,6 @@ impl From> for HostInternal { /// The host name of an URL. #[derive(Clone, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)] -#[cfg_attr(feature="heap_size", derive(HeapSizeOf))] pub enum Host { /// A DNS domain name, as '.' dot-separated labels. /// Non-ASCII labels are encoded in punycode per IDNA. @@ -55,6 +57,16 @@ pub enum Host { Ipv6(Ipv6Addr), } +#[cfg(feature = "heapsize")] +impl HeapSizeOf for Host { + fn heap_size_of_children(&self) -> usize { + match *self { + Host::Domain(ref s) => s.heap_size_of_children(), + _ => 0, + } + } +} + impl<'a> Host<&'a str> { /// Return a copy of `self` that owns an allocated `String` but does not borrow an `&Url`. pub fn to_owned(&self) -> Host { diff --git a/src/lib.rs b/src/lib.rs index 4b8bc48a5..c8b301070 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -112,17 +112,15 @@ let css_url = this_document.join("../main.css").unwrap(); assert_eq!(css_url.as_str(), "http://servo.github.io/rust-url/main.css") */ -#![cfg_attr(feature="heap_size", feature(plugin, custom_derive))] -#![cfg_attr(feature="heap_size", plugin(heapsize_plugin))] - #[cfg(feature="rustc-serialize")] extern crate rustc_serialize; #[macro_use] extern crate matches; #[cfg(feature="serde")] extern crate serde; -#[cfg(feature="heap_size")] #[macro_use] extern crate heapsize; +#[cfg(feature="heapsize")] #[macro_use] extern crate heapsize; pub extern crate idna; use encoding::EncodingOverride; +#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf; use host::HostInternal; use parser::{Parser, Context, SchemeType, to_u32}; use percent_encoding::{PATH_SEGMENT_ENCODE_SET, USERINFO_ENCODE_SET, @@ -156,7 +154,6 @@ pub mod quirks; /// A parsed URL record. #[derive(Clone)] -#[cfg_attr(feature="heap_size", derive(HeapSizeOf))] pub struct Url { /// Syntax in pseudo-BNF: /// @@ -181,6 +178,13 @@ pub struct Url { fragment_start: Option, // Before '#', unlike Position::FragmentStart } +#[cfg(feature = "heapsize")] +impl HeapSizeOf for Url { + fn heap_size_of_children(&self) -> usize { + self.serialization.heap_size_of_children() + } +} + /// Full configuration for the URL parser. #[derive(Copy, Clone)] pub struct ParseOptions<'a> { diff --git a/src/origin.rs b/src/origin.rs index a78b939fc..2217c94fe 100644 --- a/src/origin.rs +++ b/src/origin.rs @@ -6,6 +6,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#[cfg(feature = "heapsize")] use heapsize::HeapSizeOf; use host::Host; use idna::domain_to_unicode; use parser::default_port; @@ -34,7 +35,6 @@ pub fn url_origin(url: &Url) -> Origin { /// The origin of an URL #[derive(PartialEq, Eq, Clone, Debug)] -#[cfg_attr(feature="heap_size", derive(HeapSizeOf))] pub enum Origin { /// A globally unique identifier Opaque(OpaqueOrigin), @@ -43,6 +43,19 @@ pub enum Origin { Tuple(String, Host, u16) } +#[cfg(feature = "heapsize")] +impl HeapSizeOf for Origin { + fn heap_size_of_children(&self) -> usize { + match *self { + Origin::Tuple(ref scheme, ref host, _) => { + scheme.heap_size_of_children() + + host.heap_size_of_children() + }, + _ => 0, + } + } +} + impl Origin { /// Creates a new opaque origin that is only equal to itself. @@ -95,5 +108,7 @@ impl Origin { /// Opaque identifier for URLs that have file or other schemes #[derive(Eq, PartialEq, Clone, Debug)] -#[cfg_attr(feature="heap_size", derive(HeapSizeOf))] pub struct OpaqueOrigin(usize); + +#[cfg(feature = "heapsize")] +known_heap_size!(0, OpaqueOrigin);