diff options
author | Anthony Ramine <n.oxyde@gmail.com> | 2016-07-04 16:30:40 +0200 |
---|---|---|
committer | Anthony Ramine <n.oxyde@gmail.com> | 2016-07-04 16:48:14 +0200 |
commit | a5b524d5590f84428c61895b418eda7024c8e600 (patch) | |
tree | dfec847eec78e5b61dcfde29a57a1869c7a57ae9 | |
parent | 51ff916e09ff844eb2a1aa1fe2df9ef4b45af649 (diff) | |
download | servo-a5b524d5590f84428c61895b418eda7024c8e600.tar.gz servo-a5b524d5590f84428c61895b418eda7024c8e600.zip |
Move util::vec::ForgetfulSink to style::sink and simplify it
-rw-r--r-- | components/script/dom/element.rs | 6 | ||||
-rw-r--r-- | components/script/layout_wrapper.rs | 6 | ||||
-rw-r--r-- | components/servo/Cargo.lock | 1 | ||||
-rw-r--r-- | components/style/dom.rs | 4 | ||||
-rw-r--r-- | components/style/lib.rs | 1 | ||||
-rw-r--r-- | components/style/matching.rs | 2 | ||||
-rw-r--r-- | components/style/selector_matching.rs | 9 | ||||
-rw-r--r-- | components/style/sink.rs | 40 | ||||
-rw-r--r-- | components/util/Cargo.toml | 1 | ||||
-rw-r--r-- | components/util/lib.rs | 1 | ||||
-rw-r--r-- | components/util/vec.rs | 71 | ||||
-rw-r--r-- | ports/cef/Cargo.lock | 1 | ||||
-rw-r--r-- | ports/geckolib/Cargo.lock | 1 | ||||
-rw-r--r-- | ports/geckolib/wrapper.rs | 3 |
14 files changed, 58 insertions, 89 deletions
diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index 479a73dee86..d9535663d46 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -75,7 +75,6 @@ use selectors::matching::{DeclarationBlock, ElementFlags, matches}; use selectors::matching::{HAS_SLOW_SELECTOR, HAS_EDGE_CHILD_SELECTOR, HAS_SLOW_SELECTOR_LATER_SIBLINGS}; use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes}; use selectors::parser::{AttrSelector, NamespaceConstraint, parse_author_origin_selector_list_from_str}; -use smallvec::VecLike; use std::ascii::AsciiExt; use std::borrow::Cow; use std::cell::{Cell, Ref}; @@ -91,6 +90,7 @@ use style::properties::DeclaredValue; use style::properties::longhands::{self, background_image, border_spacing, font_family, overflow_x, font_size}; use style::properties::{PropertyDeclaration, PropertyDeclarationBlock, parse_style_attribute}; use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl}; +use style::sink::Push; use style::values::CSSFloat; use style::values::specified::{self, CSSColor, CSSRGBA, LengthOrPercentage}; @@ -275,7 +275,7 @@ pub trait LayoutElementHelpers { #[allow(unsafe_code)] unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>; + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>; #[allow(unsafe_code)] unsafe fn get_colspan(self) -> u32; #[allow(unsafe_code)] @@ -308,7 +308,7 @@ impl LayoutElementHelpers for LayoutJS<Element> { #[allow(unsafe_code)] unsafe fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>> { #[inline] fn from_declaration(rule: PropertyDeclaration) -> DeclarationBlock<Vec<PropertyDeclaration>> { diff --git a/components/script/layout_wrapper.rs b/components/script/layout_wrapper.rs index 681fdab9c46..779c37a5d52 100644 --- a/components/script/layout_wrapper.rs +++ b/components/script/layout_wrapper.rs @@ -49,7 +49,6 @@ use script_layout_interface::{HTMLCanvasData, LayoutNodeType, TrustedNodeAddress use script_layout_interface::{OpaqueStyleAndLayoutData, PartialStyleAndLayoutData}; use selectors::matching::{DeclarationBlock, ElementFlags}; use selectors::parser::{AttrSelector, NamespaceConstraint}; -use smallvec::VecLike; use std::marker::PhantomData; use std::mem::{transmute, transmute_copy}; use string_cache::{Atom, BorrowedAtom, BorrowedNamespace, Namespace}; @@ -63,6 +62,7 @@ use style::refcell::{Ref, RefCell, RefMut}; use style::restyle_hints::ElementSnapshot; use style::selector_impl::{NonTSPseudoClass, ServoSelectorImpl}; use style::servo::{PrivateStyleData, SharedStyleContext}; +use style::sink::Push; use url::Url; use util::str::is_whitespace; @@ -360,7 +360,7 @@ pub struct ServoLayoutElement<'le> { impl<'le> PresentationalHintsSynthetizer for ServoLayoutElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>> { unsafe { self.element.synthesize_presentational_hints_for_legacy_attributes(hints); @@ -995,5 +995,5 @@ impl <'le> ::selectors::Element for ServoThreadSafeLayoutElement<'le> { impl<'le> PresentationalHintsSynthetizer for ServoThreadSafeLayoutElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _hints: &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> {} + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>> {} } diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index b886ef4296f..4c68a576fe3 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -2471,7 +2471,6 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/components/style/dom.rs b/components/style/dom.rs index 4f7eeaff169..11cc5f93a0e 100644 --- a/components/style/dom.rs +++ b/components/style/dom.rs @@ -15,7 +15,7 @@ use restyle_hints::{ElementSnapshot, RESTYLE_DESCENDANTS, RESTYLE_LATER_SIBLINGS use selector_impl::{ElementExt, SelectorImplExt}; use selectors::Element; use selectors::matching::DeclarationBlock; -use smallvec::VecLike; +use sink::Push; use std::ops::BitOr; use std::sync::Arc; use string_cache::{Atom, Namespace}; @@ -194,7 +194,7 @@ pub trait TDocument : Sized + Copy + Clone { pub trait PresentationalHintsSynthetizer { fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, hints: &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>>; + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>>; } pub trait TElement : Sized + Copy + Clone + ElementExt + PresentationalHintsSynthetizer { diff --git a/components/style/lib.rs b/components/style/lib.rs index ae1e8c84d7c..54510250eda 100644 --- a/components/style/lib.rs +++ b/components/style/lib.rs @@ -88,6 +88,7 @@ pub mod selector_impl; pub mod selector_matching; pub mod sequential; pub mod servo; +pub mod sink; pub mod stylesheets; pub mod traversal; #[macro_use] diff --git a/components/style/matching.rs b/components/style/matching.rs index 7f865cf9a72..d3dd3742d3d 100644 --- a/components/style/matching.rs +++ b/components/style/matching.rs @@ -17,6 +17,7 @@ use selectors::Element; use selectors::bloom::BloomFilter; use selectors::matching::{CommonStyleAffectingAttributeMode, CommonStyleAffectingAttributes}; use selectors::matching::{common_style_affecting_attributes, rare_style_affecting_attributes}; +use sink::ForgetfulSink; use smallvec::SmallVec; use std::collections::HashMap; use std::hash::{BuildHasherDefault, Hash, Hasher}; @@ -26,7 +27,6 @@ use string_cache::{Atom, Namespace}; use util::arc_ptr_eq; use util::cache::{LRUCache, SimpleHashCache}; use util::opts; -use util::vec::ForgetfulSink; fn create_common_style_affecting_attributes_from_element<E: TElement>(element: &E) -> CommonStyleAffectingAttributes { diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index 35a38d5ed14..74718d4b69b 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -18,6 +18,7 @@ use selectors::bloom::BloomFilter; use selectors::matching::DeclarationBlock as GenericDeclarationBlock; use selectors::matching::{Rule, SelectorMap}; use selectors::parser::SelectorImpl; +use sink::Push; use smallvec::VecLike; use std::collections::HashMap; use std::hash::BuildHasherDefault; @@ -389,7 +390,7 @@ impl<Impl: SelectorImplExt> Stylist<Impl> { applicable_declarations: &mut V) -> bool where E: Element<Impl=Impl> + PresentationalHintsSynthetizer, - V: VecLike<DeclarationBlock> { + V: Push<DeclarationBlock> + VecLike<DeclarationBlock> { assert!(!self.is_device_dirty); assert!(style_attribute.is_none() || pseudo_element.is_none(), "Style attributes do not apply to pseudo-elements"); @@ -430,7 +431,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> { // Step 4: Normal style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.push( + Push::push( + applicable_declarations, GenericDeclarationBlock::from_declarations(sa.normal.clone())) }); @@ -443,7 +445,8 @@ impl<Impl: SelectorImplExt> Stylist<Impl> { // Step 6: `!important` style attributes. style_attribute.map(|sa| { shareable = false; - applicable_declarations.push( + Push::push( + applicable_declarations, GenericDeclarationBlock::from_declarations(sa.important.clone())) }); diff --git a/components/style/sink.rs b/components/style/sink.rs new file mode 100644 index 00000000000..33aa26ac1af --- /dev/null +++ b/components/style/sink.rs @@ -0,0 +1,40 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * 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/. */ + +use smallvec::{Array, SmallVec}; +use std::marker::PhantomData; + +pub trait Push<T> { + fn push(&mut self, value: T); +} + +impl<T> Push<T> for Vec<T> { + fn push(&mut self, value: T) { + Vec::push(self, value); + } +} + +impl<A: Array> Push<A::Item> for SmallVec<A> { + fn push(&mut self, value: A::Item) { + SmallVec::push(self, value); + } +} + +pub struct ForgetfulSink<T>(bool, PhantomData<T>); + +impl<T> ForgetfulSink<T> { + pub fn new() -> Self { + ForgetfulSink(true, PhantomData) + } + + pub fn is_empty(&self) -> bool { + self.0 + } +} + +impl<T> Push<T> for ForgetfulSink<T> { + fn push(&mut self, _value: T) { + self.0 = false; + } +} diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 83b23c78c87..b693a0f8c5b 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -31,7 +31,6 @@ rand = "0.3" rustc-serialize = "0.3" serde = {version = "0.7.11", optional = true} serde_macros = {version = "0.7.11", optional = true} -smallvec = "0.1" url = "1.0.0" [target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies] diff --git a/components/util/lib.rs b/components/util/lib.rs index 46c194ca91a..3a5c362f443 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -27,7 +27,6 @@ extern crate num_traits; extern crate rand; extern crate rustc_serialize; #[cfg(feature = "servo")] extern crate serde; -extern crate smallvec; extern crate url; #[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))] extern crate xdg; diff --git a/components/util/vec.rs b/components/util/vec.rs index 639e1c260da..2aa6b7d4a41 100644 --- a/components/util/vec.rs +++ b/components/util/vec.rs @@ -2,10 +2,6 @@ * 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/. */ -use std::marker::PhantomData; -use std::ops; -use super::smallvec::VecLike; - // TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this. pub fn byte_swap(data: &mut [u8]) { let length = data.len(); @@ -18,70 +14,3 @@ pub fn byte_swap(data: &mut [u8]) { i += 4; } } - -/// A `VecLike` that only tracks whether or not something was ever pushed to it. -pub struct ForgetfulSink<T> { - empty: bool, - _data: PhantomData<T>, -} - -impl<T> ForgetfulSink<T> { - pub fn new() -> ForgetfulSink<T> { - ForgetfulSink { - empty: true, - _data: PhantomData, - } - } - - pub fn is_empty(&self) -> bool { - self.empty - } -} - -impl<T> ops::Deref for ForgetfulSink<T> { - type Target = [T]; - fn deref(&self) -> &[T] { - unreachable!() - } -} - -impl<T> ops::DerefMut for ForgetfulSink<T> { - fn deref_mut(&mut self) -> &mut [T] { - unreachable!() - } -} - -macro_rules! impl_index { - ($index_type: ty, $output_type: ty) => { - impl<T> ops::Index<$index_type> for ForgetfulSink<T> { - type Output = $output_type; - fn index(&self, _index: $index_type) -> &$output_type { - unreachable!() - } - } - - impl<T> ops::IndexMut<$index_type> for ForgetfulSink<T> { - fn index_mut(&mut self, _index: $index_type) -> &mut $output_type { - unreachable!() - } - } - } -} - -impl_index!(usize, T); -impl_index!(ops::Range<usize>, [T]); -impl_index!(ops::RangeFrom<usize>, [T]); -impl_index!(ops::RangeTo<usize>, [T]); -impl_index!(ops::RangeFull, [T]); - -impl<T> VecLike<T> for ForgetfulSink<T> { - #[inline] - fn len(&self) -> usize { - unreachable!() - } - - #[inline] - fn push(&mut self, _value: T) { - self.empty = false; - } -} diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index 7150e137bd1..dc0b6af49f6 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -2340,7 +2340,6 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index 7b94768e030..ddd1c911aab 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -577,7 +577,6 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "xdg 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/ports/geckolib/wrapper.rs b/ports/geckolib/wrapper.rs index 83dbac01064..2c32643c008 100644 --- a/ports/geckolib/wrapper.rs +++ b/ports/geckolib/wrapper.rs @@ -50,6 +50,7 @@ use style::properties::{PropertyDeclaration, PropertyDeclarationBlock}; use style::refcell::{Ref, RefCell, RefMut}; use style::restyle_hints::ElementSnapshot; use style::selector_impl::ElementExt; +use style::sink::Push; #[allow(unused_imports)] // Used in commented-out code. use url::Url; @@ -377,7 +378,7 @@ impl<'le> TElement for GeckoElement<'le> { impl<'le> PresentationalHintsSynthetizer for GeckoElement<'le> { fn synthesize_presentational_hints_for_legacy_attributes<V>(&self, _hints: &mut V) - where V: VecLike<DeclarationBlock<Vec<PropertyDeclaration>>> + where V: Push<DeclarationBlock<Vec<PropertyDeclaration>>> { // FIXME(bholley) - Need to implement this. } |