Skip to content

Commit

Permalink
Remove use of heapsize_plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
nox committed Aug 2, 2016
1 parent a326d99 commit 8e9ce4a
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 12 deletions.
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
16 changes: 14 additions & 2 deletions src/host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -16,14 +17,16 @@ 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,
Ipv4(Ipv4Addr),
Ipv6(Ipv6Addr),
}

#[cfg(feature = "heapsize")]
known_heap_size!(0, HostInternal);

impl<S> From<Host<S>> for HostInternal {
fn from(host: Host<S>) -> HostInternal {
match host {
Expand All @@ -36,7 +39,6 @@ impl<S> From<Host<S>> 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<S=String> {
/// A DNS domain name, as '.' dot-separated labels.
/// Non-ASCII labels are encoded in punycode per IDNA.
Expand All @@ -55,6 +57,16 @@ pub enum Host<S=String> {
Ipv6(Ipv6Addr),
}

#[cfg(feature = "heapsize")]
impl<S: HeapSizeOf> HeapSizeOf for Host<S> {
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<String> {
Expand Down
14 changes: 9 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
///
Expand All @@ -181,6 +178,13 @@ pub struct Url {
fragment_start: Option<u32>, // 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> {
Expand Down
19 changes: 17 additions & 2 deletions src/origin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -43,6 +43,19 @@ pub enum Origin {
Tuple(String, Host<String>, 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.
Expand Down Expand Up @@ -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);

0 comments on commit 8e9ce4a

Please sign in to comment.