Просмотр исходного кода

Auto merge of #123 - notriddle:master, r=SimonSapin

Add heapsize support.

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/rust-url/123)
<!-- Reviewable:end -->
bors-servo 11 лет назад
Родитель
Сommit
8dd7821b1b
4 измененных файлов с 23 добавлено и 0 удалено
  1. 9 0
      Cargo.toml
  2. 1 0
      Makefile
  3. 3 0
      src/host.rs
  4. 10 0
      src/lib.rs

+ 9 - 0
Cargo.toml

@@ -14,6 +14,15 @@ license = "MIT/Apache-2.0"
 [features]
 query_encoding = ["encoding"]
 serde_serialization = ["serde"]
+heap_size = ["heapsize", "heapsize_plugin"]
+
+[dependencies.heapsize]
+version = "0.1.1"
+optional = true
+
+[dependencies.heapsize_plugin]
+version = "0.0.1"
+optional = true
 
 [dependencies.encoding]
 version = "0.2"

+ 1 - 0
Makefile

@@ -2,6 +2,7 @@ test:
 	cargo test --features query_encoding
 	cargo test --features serde_serialization
 	cargo test
+	[ x$$TRAVIS_RUST_VERSION != xnightly ] || cargo test --features heap_size
 
 doc:
 	cargo doc --features "query_encoding serde_serialization"

+ 3 - 0
src/host.rs

@@ -15,6 +15,7 @@ use percent_encoding::{from_hex, percent_decode};
 
 /// The host name of an URL.
 #[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub enum Host {
     /// A (DNS) domain name or an IPv4 address.
     ///
@@ -34,6 +35,8 @@ pub enum Host {
 pub struct Ipv6Address {
     pub pieces: [u16; 8]
 }
+#[cfg(feature="heap_size")]
+known_heap_size!(0, Ipv6Address);
 
 
 impl Host {

+ 10 - 0
src/lib.rs

@@ -118,6 +118,9 @@ assert!(css_url.serialize() == "http://servo.github.io/rust-url/main.css".to_str
 
 */
 
+#![cfg_attr(feature="heap_size", feature(plugin, custom_derive))]
+#![cfg_attr(feature="heap_size", plugin(heapsize_plugin))]
+
 extern crate rustc_serialize;
 
 #[macro_use]
@@ -126,6 +129,9 @@ extern crate matches;
 #[cfg(feature="serde_serialization")]
 extern crate serde;
 
+#[cfg(feature="heap_size")]
+#[macro_use] extern crate heapsize;
+
 use std::fmt::{self, Formatter};
 use std::str;
 use std::path::{Path, PathBuf};
@@ -156,6 +162,7 @@ mod tests;
 
 /// The parsed representation of an absolute URL.
 #[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub struct Url {
     /// The scheme (a.k.a. protocol) of the URL, in ASCII lower case.
     pub scheme: String,
@@ -187,6 +194,7 @@ pub struct Url {
 
 /// The components of the URL whose representation depends on where the scheme is *relative*.
 #[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub enum SchemeData {
     /// Components for URLs in a *relative* scheme such as HTTP.
     Relative(RelativeSchemeData),
@@ -201,6 +209,7 @@ pub enum SchemeData {
 
 /// Components for URLs in a *relative* scheme such as HTTP.
 #[derive(PartialEq, Eq, Clone, Debug, Hash, PartialOrd, Ord)]
+#[cfg_attr(feature="heap_size", derive(HeapSizeOf))]
 pub struct RelativeSchemeData {
     /// The username of the URL, as a possibly empty, percent-encoded string.
     ///
@@ -1048,3 +1057,4 @@ fn file_url_path_to_pathbuf_windows(path: &[String]) -> Result<PathBuf, ()> {
                   "to_file_path() failed to produce an absolute Path");
     Ok(path)
 }
+