From 0adc02a317364166d71bd7374857a6bada5e7c90 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Emilio=20Cobos=20=C3=81lvarez?= Date: Mon, 29 May 2017 23:24:06 +0200 Subject: [PATCH] style: Avoid some cfg checks in context.rs --- components/layout/animation.rs | 8 ++++---- components/layout_thread/lib.rs | 18 ++++++++---------- components/style/context.rs | 10 +++++----- 3 files changed, 17 insertions(+), 19 deletions(-) diff --git a/components/layout/animation.rs b/components/layout/animation.rs index a054927190c..5d7a1a87acc 100644 --- a/components/layout/animation.rs +++ b/components/layout/animation.rs @@ -6,13 +6,13 @@ use context::LayoutContext; use flow::{self, Flow}; +use fnv::FnvHashMap; use gfx::display_list::OpaqueNode; use ipc_channel::ipc::IpcSender; use msg::constellation_msg::PipelineId; use opaque_node::OpaqueNodeMethods; use script_traits::{AnimationState, ConstellationControlMsg, LayoutMsg as ConstellationMsg}; use script_traits::UntrustedNodeAddress; -use std::collections::HashMap; use std::sync::mpsc::Receiver; use style::animation::{Animation, update_style_for_animation}; use style::font_metrics::ServoMetricsProvider; @@ -24,8 +24,8 @@ use style::timer::Timer; /// `expired_animations`. pub fn update_animation_state(constellation_chan: &IpcSender, script_chan: &IpcSender, - running_animations: &mut HashMap>, - expired_animations: &mut HashMap>, + running_animations: &mut FnvHashMap>, + expired_animations: &mut FnvHashMap>, mut newly_transitioning_nodes: Option<&mut Vec>, new_animations_receiver: &Receiver, pipeline_id: PipelineId, @@ -149,7 +149,7 @@ pub fn update_animation_state(constellation_chan: &IpcSender, // this should be made generic. pub fn recalc_style_for_animations(context: &LayoutContext, flow: &mut Flow, - animations: &HashMap>) { let mut damage = RestyleDamage::empty(); flow.mutate_fragments(&mut |fragment| { diff --git a/components/layout_thread/lib.rs b/components/layout_thread/lib.rs index 32cf5dc23a3..9ddff21070e 100644 --- a/components/layout_thread/lib.rs +++ b/components/layout_thread/lib.rs @@ -44,7 +44,7 @@ use euclid::point::Point2D; use euclid::rect::Rect; use euclid::scale_factor::ScaleFactor; use euclid::size::Size2D; -use fnv::FnvHasher; +use fnv::FnvHashMap; use gfx::display_list::{OpaqueNode, WebRenderImageInfo}; use gfx::font; use gfx::font_cache_thread::FontCacheThread; @@ -99,7 +99,6 @@ use servo_url::ServoUrl; use std::borrow::ToOwned; use std::cell::{Cell, RefCell}; use std::collections::HashMap; -use std::hash::BuildHasherDefault; use std::marker::PhantomData; use std::mem as std_mem; use std::ops::{Deref, DerefMut}; @@ -203,10 +202,10 @@ pub struct LayoutThread { document_shared_lock: Option, /// The list of currently-running animations. - running_animations: StyleArc>>>, + running_animations: StyleArc>>>, /// The list of animations that have expired since the last style recalculation. - expired_animations: StyleArc>>>, + expired_animations: StyleArc>>>, /// A counter for epoch messages epoch: Cell, @@ -224,9 +223,8 @@ pub struct LayoutThread { /// The CSS error reporter for all CSS loaded in this layout thread error_reporter: CSSErrorReporter, - webrender_image_cache: Arc>>>, + webrender_image_cache: Arc>>, /// Webrender interface. webrender_api: webrender_traits::RenderApi, @@ -492,8 +490,8 @@ impl LayoutThread { outstanding_web_fonts: outstanding_web_fonts_counter, root_flow: RefCell::new(None), document_shared_lock: None, - running_animations: StyleArc::new(RwLock::new(HashMap::new())), - expired_animations: StyleArc::new(RwLock::new(HashMap::new())), + running_animations: StyleArc::new(RwLock::new(FnvHashMap::default())), + expired_animations: StyleArc::new(RwLock::new(FnvHashMap::default())), epoch: Cell::new(Epoch(0)), viewport_size: Size2D::new(Au(0), Au(0)), webrender_api: webrender_api_sender.create_api(), @@ -521,7 +519,7 @@ impl LayoutThread { script_chan: Arc::new(Mutex::new(script_chan)), }, webrender_image_cache: - Arc::new(RwLock::new(HashMap::with_hasher(Default::default()))), + Arc::new(RwLock::new(FnvHashMap::default())), timer: if PREFS.get("layout.animations.test.enabled") .as_boolean().unwrap_or(false) { diff --git a/components/style/context.rs b/components/style/context.rs index ee50e953980..1214040dcf4 100644 --- a/components/style/context.rs +++ b/components/style/context.rs @@ -20,11 +20,8 @@ use font_metrics::FontMetricsProvider; #[cfg(feature = "gecko")] use properties::ComputedValues; use selector_parser::SnapshotMap; use selectors::matching::ElementSelectorFlags; -#[cfg(feature = "servo")] use servo_config::opts; use shared_lock::StylesheetGuards; use sharing::{CachedStyleSharingData, StyleSharingCandidateCache}; -#[cfg(feature = "servo")] use std::collections::HashMap; -#[cfg(feature = "gecko")] use std::env; use std::fmt; use std::ops::Add; #[cfg(feature = "servo")] use std::sync::Mutex; @@ -78,6 +75,7 @@ pub struct StyleSystemOptions { #[cfg(feature = "gecko")] fn get_env(name: &str) -> bool { + use std::env; match env::var(name) { Ok(s) => !s.is_empty(), Err(_) => false, @@ -87,6 +85,8 @@ fn get_env(name: &str) -> bool { impl Default for StyleSystemOptions { #[cfg(feature = "servo")] fn default() -> Self { + use servo_config::opts; + StyleSystemOptions { disable_style_sharing_cache: opts::get().disable_share_style_cache, dump_style_statistics: opts::get().style_sharing_stats, @@ -134,11 +134,11 @@ pub struct SharedStyleContext<'a> { /// The animations that are currently running. #[cfg(feature = "servo")] - pub running_animations: Arc>>>, + pub running_animations: Arc>>>, /// The list of animations that have expired since the last style recalculation. #[cfg(feature = "servo")] - pub expired_animations: Arc>>>, + pub expired_animations: Arc>>>, /// Data needed to create the thread-local style context from the shared one. #[cfg(feature = "servo")]