Skip to content

Commit

Permalink
Add HeapSizeOf support.
Browse files Browse the repository at this point in the history
  • Loading branch information
notriddle committed Aug 13, 2015
1 parent e4d0af9 commit bf21a04
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 6 deletions.
21 changes: 19 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,33 @@ license = "MPL-2.0"

[features]
unstable = ["string_cache_plugin", "string_cache/unstable"]
heap_size = ["string_cache/heap_size", "heapsize", "heapsize_plugin"]

[dependencies]
bitflags = "0.3"
matches = "0.1"
cssparser = "0.3"
smallvec = "0.1"
fnv = "1.0"
string_cache = "0.1.10"
string_cache_plugin = { version = "0.1.6", optional = true }
#string_cache = "0.1.10"
#string_cache_plugin = { version = "0.1.6", optional = true }
quickersort = "1.0.0"

[dependencies.string_cache]
git = "https://github.com/servo/string-cache"

[dependencies.string_cache_plugin]
git = "https://github.com/servo/string-cache"
optional = true

[dependencies.heapsize]
version = "0.1.1"
features = [ "unstable" ]
optional = true

[dependencies.heapsize_plugin]
version = "0.0.1"
optional = true

[dev-dependencies]
rand = "0.3"
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#![cfg_attr(feature = "unstable", feature(plugin, hashmap_hasher))]
#![cfg_attr(feature = "unstable", feature(plugin, hashmap_hasher, custom_derive))]
#![cfg_attr(feature = "unstable", plugin(string_cache_plugin))]
#![cfg_attr(all(test, feature = "unstable"), feature(test))]
#![cfg_attr(feature = "heap_size", feature(plugin, custom_derive))]
#![cfg_attr(feature = "heap_size", plugin(heapsize_plugin))]

#[cfg(feature = "heap_size")] extern crate heapsize;
#[macro_use] extern crate bitflags;
#[macro_use] extern crate cssparser;
#[macro_use] extern crate matches;
Expand Down
4 changes: 3 additions & 1 deletion src/matching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ pub static SELECTOR_WHITESPACE: &'static [char] = &[' ', '\t', '\n', '\r', '\x0C
/// Hence, the union of the rules keyed on each of element's classes, ID,
/// element name, etc. will contain the Rules that actually match that
/// element.
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct SelectorMap<T> {
// TODO: Tune the initial capacity of the HashMap
id_hash: HashMap<Atom, Vec<Rule<T>>>,
Expand Down Expand Up @@ -232,7 +233,7 @@ impl<T> SelectorMap<T> {
// rapidly increase.
pub static RECOMMENDED_SELECTOR_BLOOM_FILTER_SIZE: usize = 4096;


#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct Rule<T> {
// This is an Arc because Rule will essentially be cloned for every element
// that it matches. Selector contains an owned vector (through
Expand All @@ -243,6 +244,7 @@ pub struct Rule<T> {

/// A property declaration together with its precedence among rules of equal specificity so that
/// we can sort them.
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(Debug)]
pub struct DeclarationBlock<T> {
pub declarations: Arc<T>,
Expand Down
11 changes: 9 additions & 2 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,28 +28,30 @@ impl ParserContext {
}
}


#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(PartialEq, Clone, Debug)]
pub struct Selector {
pub compound_selectors: Arc<CompoundSelector>,
pub pseudo_element: Option<PseudoElement>,
pub specificity: u32,
}

#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(Eq, PartialEq, Clone, Hash, Copy, Debug)]
pub enum PseudoElement {
Before,
After,
// ...
}


#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(PartialEq, Clone, Debug)]
pub struct CompoundSelector {
pub simple_selectors: Vec<SimpleSelector>,
pub next: Option<(Box<CompoundSelector>, Combinator)>, // c.next is left of c
}

#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(PartialEq, Clone, Copy, Debug)]
pub enum Combinator {
Child, // >
Expand All @@ -58,6 +60,7 @@ pub enum Combinator {
LaterSibling, // ~
}

#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
#[derive(Eq, PartialEq, Clone, Hash, Debug)]
pub enum SimpleSelector {
ID(Atom),
Expand Down Expand Up @@ -101,26 +104,30 @@ pub enum SimpleSelector {


#[derive(Eq, PartialEq, Clone, Hash, Copy, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub enum CaseSensitivity {
CaseSensitive, // Selectors spec says language-defined, but HTML says sensitive.
CaseInsensitive,
}


#[derive(Eq, PartialEq, Clone, Hash, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct LocalName {
pub name: Atom,
pub lower_name: Atom,
}

#[derive(Eq, PartialEq, Clone, Hash, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub struct AttrSelector {
pub name: Atom,
pub lower_name: Atom,
pub namespace: NamespaceConstraint,
}

#[derive(Eq, PartialEq, Clone, Hash, Debug)]
#[cfg_attr(feature = "heap_size", derive(HeapSizeOf))]
pub enum NamespaceConstraint {
Any,
Specific(Namespace),
Expand Down

0 comments on commit bf21a04

Please sign in to comment.