Skip to content

Commit

Permalink
Revert "Diagnostic map semantics."
Browse files Browse the repository at this point in the history
This reverts commit f5c5be0.
  • Loading branch information
Manishearth committed Oct 23, 2017
1 parent d6bafde commit b118ba7
Show file tree
Hide file tree
Showing 11 changed files with 68 additions and 296 deletions.
143 changes: 0 additions & 143 deletions components/hashglobe/src/diagnostic.rs

This file was deleted.

14 changes: 0 additions & 14 deletions components/hashglobe/src/fake.rs
Expand Up @@ -76,24 +76,10 @@ impl<K, V, S> HashMap<K, V, S>
Ok(self.entry(key))
}

#[inline(always)]
pub fn try_get_or_insert_with<F: FnOnce() -> V>(
&mut self,
key: K,
default: F
) -> Result<&mut V, FailedAllocationError> {
Ok(self.entry(key).or_insert_with(default))
}

#[inline]
pub fn try_insert(&mut self, k: K, v: V) -> Result<Option<V>, FailedAllocationError> {
Ok(self.insert(k, v))
}

#[inline(always)]
pub fn begin_mutation(&mut self) {}
#[inline(always)]
pub fn end_mutation(&mut self) {}
}

#[derive(Clone)]
Expand Down
1 change: 0 additions & 1 deletion components/hashglobe/src/lib.rs
Expand Up @@ -9,7 +9,6 @@
// except according to those terms.

pub mod alloc;
pub mod diagnostic;
pub mod hash_map;
pub mod hash_set;
mod shim;
Expand Down
19 changes: 0 additions & 19 deletions components/malloc_size_of/lib.rs
Expand Up @@ -499,25 +499,6 @@ impl<K, V, S> MallocSizeOf for hashglobe::hash_map::HashMap<K, V, S>
}
}

impl<K, V, S> MallocShallowSizeOf for hashglobe::diagnostic::DiagnosticHashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher
{
fn shallow_size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.inner().shallow_size_of(ops)
}
}

impl<K, V, S> MallocSizeOf for hashglobe::diagnostic::DiagnosticHashMap<K, V, S>
where K: Eq + Hash + MallocSizeOf,
V: MallocSizeOf,
S: BuildHasher,
{
fn size_of(&self, ops: &mut MallocSizeOfOps) -> usize {
self.inner().size_of(ops)
}
}

impl<K, V, S> MallocShallowSizeOf for hashglobe::fake::HashMap<K, V, S>
where K: Eq + Hash,
S: BuildHasher,
Expand Down
6 changes: 6 additions & 0 deletions components/style/context.rs
Expand Up @@ -322,6 +322,8 @@ pub struct TraversalStatistics {
pub selectors: u32,
/// The number of revalidation selectors.
pub revalidation_selectors: u32,
/// The number of state/attr dependencies in the dependency set.
pub dependency_selectors: u32,
/// The number of declarations in the stylist.
pub declarations: u32,
/// The number of times the stylist was rebuilt.
Expand All @@ -342,6 +344,7 @@ impl<'a> ops::Add for &'a TraversalStatistics {
"traversal_time_ms should be set at the end by the caller");
debug_assert!(self.selectors == 0, "set at the end");
debug_assert!(self.revalidation_selectors == 0, "set at the end");
debug_assert!(self.dependency_selectors == 0, "set at the end");
debug_assert!(self.declarations == 0, "set at the end");
debug_assert!(self.stylist_rebuilds == 0, "set at the end");
TraversalStatistics {
Expand All @@ -352,6 +355,7 @@ impl<'a> ops::Add for &'a TraversalStatistics {
styles_reused: self.styles_reused + other.styles_reused,
selectors: 0,
revalidation_selectors: 0,
dependency_selectors: 0,
declarations: 0,
stylist_rebuilds: 0,
traversal_time_ms: 0.0,
Expand Down Expand Up @@ -379,6 +383,7 @@ impl fmt::Display for TraversalStatistics {
writeln!(f, "[PERF],styles_reused,{}", self.styles_reused)?;
writeln!(f, "[PERF],selectors,{}", self.selectors)?;
writeln!(f, "[PERF],revalidation_selectors,{}", self.revalidation_selectors)?;
writeln!(f, "[PERF],dependency_selectors,{}", self.dependency_selectors)?;
writeln!(f, "[PERF],declarations,{}", self.declarations)?;
writeln!(f, "[PERF],stylist_rebuilds,{}", self.stylist_rebuilds)?;
writeln!(f, "[PERF],traversal_time_ms,{}", self.traversal_time_ms)?;
Expand All @@ -400,6 +405,7 @@ impl TraversalStatistics {
self.traversal_time_ms = (time::precise_time_s() - start) * 1000.0;
self.selectors = stylist.num_selectors() as u32;
self.revalidation_selectors = stylist.num_revalidation_selectors() as u32;
self.dependency_selectors = stylist.num_invalidations() as u32;
self.declarations = stylist.num_declarations() as u32;
self.stylist_rebuilds = stylist.num_rebuilds() as u32;
}
Expand Down
17 changes: 6 additions & 11 deletions components/style/custom_properties.rs
Expand Up @@ -10,7 +10,7 @@ use Atom;
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
use precomputed_hash::PrecomputedHash;
use properties::{CSSWideKeyword, DeclaredValue};
use selector_map::{PrecomputedHashSet, PrecomputedHashMap, PrecomputedDiagnosticHashMap};
use selector_map::{PrecomputedHashSet, PrecomputedHashMap};
use selectors::parser::SelectorParseErrorKind;
use servo_arc::Arc;
use smallvec::SmallVec;
Expand Down Expand Up @@ -88,7 +88,7 @@ where
/// Key index.
index: Vec<K>,
/// Key-value map.
values: PrecomputedDiagnosticHashMap<K, V>,
values: PrecomputedHashMap<K, V>,
}

impl<K, V> OrderedMap<K, V>
Expand All @@ -99,7 +99,7 @@ where
pub fn new() -> Self {
OrderedMap {
index: Vec::new(),
values: PrecomputedDiagnosticHashMap::default(),
values: PrecomputedHashMap::default(),
}
}

Expand All @@ -108,9 +108,7 @@ where
if !self.values.contains_key(&key) {
self.index.push(key.clone());
}
self.values.begin_mutation();
self.values.try_insert(key, value).unwrap();
self.values.end_mutation();
self.values.insert(key, value);
}

/// Get a value given its key.
Expand Down Expand Up @@ -160,10 +158,7 @@ where
None => return None,
};
self.index.remove(index);
self.values.begin_mutation();
let result = self.values.remove(key);
self.values.end_mutation();
result
self.values.remove(key)
}

fn remove_set<S>(&mut self, set: &::hash::HashSet<K, S>)
Expand Down Expand Up @@ -211,7 +206,7 @@ where
};

self.pos += 1;
let value = &self.inner.values.get(key).unwrap();
let value = &self.inner.values[key];

Some((key, value))
}
Expand Down
7 changes: 1 addition & 6 deletions components/style/hash.rs
Expand Up @@ -13,15 +13,10 @@ use fnv;
pub use hashglobe::hash_map::HashMap;
#[cfg(feature = "gecko")]
pub use hashglobe::hash_set::HashSet;
#[cfg(feature = "gecko")]
pub use hashglobe::diagnostic::DiagnosticHashMap;

#[cfg(feature = "servo")]
pub use hashglobe::fake::{HashMap, HashSet};

/// Alias to use regular HashMaps everywhere in Servo.
#[cfg(feature = "servo")]
pub type DiagnosticHashMap<K, V, S> = HashMap<K, V, S>;
pub use hashglobe::fake::{HashMap, HashSet};

/// Appropriate reexports of hash_map types
pub mod map {
Expand Down
34 changes: 16 additions & 18 deletions components/style/invalidation/element/invalidation_map.rs
Expand Up @@ -172,6 +172,18 @@ impl InvalidationMap {
}
}

/// Returns the number of dependencies stored in the invalidation map.
pub fn len(&self) -> usize {
self.state_affecting_selectors.len() +
self.other_attribute_affecting_selectors.len() +
self.id_to_selector.iter().fold(0, |accum, (_, ref v)| {
accum + v.len()
}) +
self.class_to_selector.iter().fold(0, |accum, (_, ref v)| {
accum + v.len()
})
}

/// Adds a selector to this `InvalidationMap`. Returns Err(..) to
/// signify OOM.
pub fn note_selector(
Expand Down Expand Up @@ -234,7 +246,8 @@ impl InvalidationMap {

for class in compound_visitor.classes {
self.class_to_selector
.try_get_or_insert_with(class, quirks_mode, SmallVec::new)?
.entry(class, quirks_mode)
.or_insert_with(SmallVec::new)
.try_push(Dependency {
selector: selector.clone(),
selector_offset: sequence_start,
Expand All @@ -243,7 +256,8 @@ impl InvalidationMap {

for id in compound_visitor.ids {
self.id_to_selector
.try_get_or_insert_with(id, quirks_mode, SmallVec::new)?
.entry(id, quirks_mode)
.or_insert_with(SmallVec::new)
.try_push(Dependency {
selector: selector.clone(),
selector_offset: sequence_start,
Expand Down Expand Up @@ -279,22 +293,6 @@ impl InvalidationMap {

Ok(())
}

/// Allows mutation of this InvalidationMap.
pub fn begin_mutation(&mut self) {
self.class_to_selector.begin_mutation();
self.id_to_selector.begin_mutation();
self.state_affecting_selectors.begin_mutation();
self.other_attribute_affecting_selectors.begin_mutation();
}

/// Disallows mutation of this InvalidationMap.
pub fn end_mutation(&mut self) {
self.class_to_selector.end_mutation();
self.id_to_selector.end_mutation();
self.state_affecting_selectors.end_mutation();
self.other_attribute_affecting_selectors.end_mutation();
}
}

/// A struct that collects invalidations for a given compound selector.
Expand Down

0 comments on commit b118ba7

Please sign in to comment.