From f1b251a4423891b21ee30a074f1f1595465986da Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 30 Jul 2016 15:34:34 +0200 Subject: [PATCH 1/4] Reorder dependencies --- Cargo.toml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e0f6596a..b616565a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -30,10 +30,10 @@ query_encoding = ["encoding"] heap_size = ["heapsize", "heapsize_plugin"] [dependencies] -idna = { version = "0.1.0", path = "./idna" } +encoding = {version = "0.2", optional = true} heapsize = {version = ">=0.1.1, <0.4", optional = true} heapsize_plugin = {version = "0.1.0", optional = true} -encoding = {version = "0.2", optional = true} -serde = {version = ">=0.6.1, <0.8", optional = true} -rustc-serialize = {version = "0.3", optional = true} +idna = { version = "0.1.0", path = "./idna" } matches = "0.1" +rustc-serialize = {version = "0.3", optional = true} +serde = {version = ">=0.6.1, <0.8", optional = true} From a326d99bb8f89c7d114aa6880468d8402f108a9f Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 30 Jul 2016 15:35:45 +0200 Subject: [PATCH 2/4] Allow serde 0.8 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index b616565a..b97d38ee 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,4 +36,4 @@ 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} -serde = {version = ">=0.6.1, <0.8", optional = true} +serde = {version = ">=0.6.1, <0.9", optional = true} From 8e9ce4a34e69e474c6a4391e9cf64cf612206108 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 30 Jul 2016 15:42:08 +0200 Subject: [PATCH 3/4] Remove use of heapsize_plugin --- Cargo.toml | 3 +-- Makefile | 2 +- src/host.rs | 16 ++++++++++++++-- src/lib.rs | 14 +++++++++----- src/origin.rs | 19 +++++++++++++++++-- 5 files changed, 42 insertions(+), 12 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index b97d38ee..21eedbd1 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 a80d8a5f..7441b664 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 11950a6f..47b049a2 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 4b8bc48a..c8b30107 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 a78b939f..2217c94f 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); From 9f2f5821d9079574156f93c48ea0a4f18d14964a Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Sat, 30 Jul 2016 15:42:24 +0200 Subject: [PATCH 4/4] Bump version to 1.2.0 --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index 21eedbd1..fd147f37 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "url" -version = "1.1.1" +version = "1.2.0" authors = ["The rust-url developers"] description = "URL library for Rust, based on the WHATWG URL Standard"