From 304108417665a7c4a43cedde7bb9979adeab4883 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Jun 2016 17:23:04 +0200 Subject: [PATCH 1/3] Move util::linked_list to layout --- components/layout/construct.rs | 5 ++--- components/layout/lib.rs | 1 + components/{util => layout}/linked_list.rs | 0 components/layout/text.rs | 2 +- components/util/lib.rs | 1 - 5 files changed, 4 insertions(+), 5 deletions(-) rename components/{util => layout}/linked_list.rs (100%) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 40ffdc42047..9f342b321a9 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -30,6 +30,7 @@ use fragment::{InlineBlockFragmentInfo, SpecificFragmentInfo, UnscannedTextFragm use gfx::display_list::OpaqueNode; use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFlow, InlineFragmentNodeFlags}; use inline::{InlineFragmentNodeInfo, LAST_FRAGMENT_OF_ELEMENT}; +use linked_list::prepend_from; use list_item::{ListItemFlow, ListStyleTypeContent}; use multicol::{MulticolFlow, MulticolColumnFlow}; use parallel; @@ -57,7 +58,6 @@ use table_wrapper::TableWrapperFlow; use text::TextRunScanner; use traversal::PostorderNodeMutTraversal; use url::Url; -use util::linked_list; use util::opts; use wrapper::{TextContent, ThreadSafeLayoutNodeHelpers}; @@ -1805,8 +1805,7 @@ pub fn strip_ignorable_whitespace_from_start(this: &mut LinkedList) { } } } - linked_list::prepend_from(this, - &mut leading_fragments_consisting_of_solely_bidi_control_characters); + prepend_from(this, &mut leading_fragments_consisting_of_solely_bidi_control_characters); } /// Strips ignorable whitespace from the end of a list of fragments. diff --git a/components/layout/lib.rs b/components/layout/lib.rs index e747993dd84..f05b21c3628 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -75,6 +75,7 @@ mod fragment; mod generated_content; pub mod incremental; mod inline; +mod linked_list; mod list_item; mod model; mod multicol; diff --git a/components/util/linked_list.rs b/components/layout/linked_list.rs similarity index 100% rename from components/util/linked_list.rs rename to components/layout/linked_list.rs diff --git a/components/layout/text.rs b/components/layout/text.rs index 472ef9fcd50..250ad9d5e73 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -16,6 +16,7 @@ use gfx::text::glyph::ByteIndex; use gfx::text::text_run::TextRun; use gfx::text::util::{self, CompressionMode}; use inline::{FIRST_FRAGMENT_OF_ELEMENT, InlineFragments, LAST_FRAGMENT_OF_ELEMENT}; +use linked_list::split_off_head; use range::Range; use std::borrow::ToOwned; use std::collections::LinkedList; @@ -28,7 +29,6 @@ use style::properties::style_structs::ServoFont; use style::properties::{ComputedValues, ServoComputedValues}; use unicode_bidi::{is_rtl, process_text}; use unicode_script::{get_script, Script}; -use util::linked_list::split_off_head; /// Returns the concatenated text of a list of unscanned text fragments. fn text(fragments: &LinkedList) -> String { diff --git a/components/util/lib.rs b/components/util/lib.rs index ff1a18ab712..eed9c3e2a98 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -39,7 +39,6 @@ pub mod cache; #[allow(unsafe_code)] pub mod debug_utils; pub mod geometry; #[cfg(feature = "servo")] #[allow(unsafe_code)] pub mod ipc; -#[cfg(feature = "servo")] pub mod linked_list; #[allow(unsafe_code)] pub mod opts; #[cfg(feature = "servo")] pub mod panicking; pub mod prefs; From f8f00fac5b2612ce857cca4cdae99c1205beec70 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Jun 2016 17:35:13 +0200 Subject: [PATCH 2/3] Move util::time::duration_from_nanoseconds to its only caller --- components/compositing/delayed_composition.rs | 15 ++++++++++++++- components/util/time.rs | 11 ----------- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/components/compositing/delayed_composition.rs b/components/compositing/delayed_composition.rs index c2ae4b86fa9..36c0306011a 100644 --- a/components/compositing/delayed_composition.rs +++ b/components/compositing/delayed_composition.rs @@ -10,8 +10,9 @@ use compositor_thread::{CompositorProxy, Msg}; use std::sync::mpsc::{Receiver, Sender, channel}; use std::thread::{self, Builder}; +use std::time::Duration; +use std::u32; use time; -use util::time::duration_from_nanoseconds; /// The amount of time in nanoseconds that we give to the painting thread to paint. When this /// expires, we give up and composite anyway. @@ -92,3 +93,15 @@ impl DelayedCompositionTimer { } } +fn duration_from_nanoseconds(nanos: u64) -> Duration { + pub const NANOS_PER_SEC: u32 = 1_000_000_000; + + // Get number of seconds. + let secs = nanos / NANOS_PER_SEC as u64; + + // Get number of extra nanoseconds. This should always fit in a u32, but check anyway. + let subsec_nanos = nanos % NANOS_PER_SEC as u64; + assert!(subsec_nanos <= u32::MAX as u64); + + Duration::new(secs, subsec_nanos as u32) +} diff --git a/components/util/time.rs b/components/util/time.rs index 4a751c95ee1..dab092b8850 100644 --- a/components/util/time.rs +++ b/components/util/time.rs @@ -18,14 +18,3 @@ pub fn duration_from_seconds(secs: f64) -> Duration { Duration::new(whole_secs as u64, nanos as u32) } - -pub fn duration_from_nanoseconds(nanos: u64) -> Duration { - // Get number of seconds. - let secs = nanos / NANOS_PER_SEC as u64; - - // Get number of extra nanoseconds. This should always fit in a u32, but check anyway. - let subsec_nanos = nanos % NANOS_PER_SEC as u64; - assert!(subsec_nanos <= u32::MAX as u64); - - Duration::new(secs, subsec_nanos as u32) -} From 5a576e873e34eca47446850d41d5a33048a6ad21 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Wed, 29 Jun 2016 17:44:17 +0200 Subject: [PATCH 3/3] Move util::time::duration_from_seconds to profile::time --- components/profile/mem.rs | 2 +- components/profile/time.rs | 17 +++++++++++++++-- components/util/lib.rs | 1 - components/util/time.rs | 20 -------------------- 4 files changed, 16 insertions(+), 24 deletions(-) delete mode 100644 components/util/time.rs diff --git a/components/profile/mem.rs b/components/profile/mem.rs index 297584891c2..d1d2ca26b20 100644 --- a/components/profile/mem.rs +++ b/components/profile/mem.rs @@ -12,8 +12,8 @@ use std::borrow::ToOwned; use std::cmp::Ordering; use std::collections::HashMap; use std::thread; +use time::duration_from_seconds; use util::thread::spawn_named; -use util::time::duration_from_seconds; pub struct Profiler { /// The port through which messages are received. diff --git a/components/profile/time.rs b/components/profile/time.rs index 9c310fe9270..9c9debdb738 100644 --- a/components/profile/time.rs +++ b/components/profile/time.rs @@ -19,12 +19,11 @@ use std::io::{self, Write}; use std::path; use std::path::Path; use std::time::Duration; -use std::{thread, f64}; +use std::{f64, thread, u32, u64}; use std_time::precise_time_ns; use trace_dump::TraceDump; use util::opts::OutputOptions; use util::thread::spawn_named; -use util::time::duration_from_seconds; pub trait Formattable { fn format(&self, output: &Option) -> String; @@ -408,3 +407,17 @@ fn enforce_range(min: T, max: T, value: T) -> T where T: Ord { }, } } + +pub fn duration_from_seconds(secs: f64) -> Duration { + pub const NANOS_PER_SEC: u32 = 1_000_000_000; + + // Get number of seconds and check that it fits in a u64. + let whole_secs = secs.trunc(); + assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64); + + // Get number of nanoseconds. This should always fit in a u32, but check anyway. + let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc(); + assert!(nanos >= 0.0 && nanos <= u32::MAX as f64); + + Duration::new(whole_secs as u64, nanos as u32) +} diff --git a/components/util/lib.rs b/components/util/lib.rs index eed9c3e2a98..eb71fdf41f1 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -48,7 +48,6 @@ pub mod str; pub mod thread; pub mod thread_state; pub mod tid; -#[cfg(feature = "servo")] pub mod time; pub mod vec; #[allow(unsafe_code)] pub mod workqueue; diff --git a/components/util/time.rs b/components/util/time.rs deleted file mode 100644 index dab092b8850..00000000000 --- a/components/util/time.rs +++ /dev/null @@ -1,20 +0,0 @@ -/* 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 std::time::Duration; -use std::{u32, u64}; - -pub const NANOS_PER_SEC: u32 = 1_000_000_000; - -pub fn duration_from_seconds(secs: f64) -> Duration { - // Get number of seconds and check that it fits in a u64. - let whole_secs = secs.trunc(); - assert!(whole_secs >= 0.0 && whole_secs <= u64::MAX as f64); - - // Get number of nanoseconds. This should always fit in a u32, but check anyway. - let nanos = (secs.fract() * (NANOS_PER_SEC as f64)).trunc(); - assert!(nanos >= 0.0 && nanos <= u32::MAX as f64); - - Duration::new(whole_secs as u64, nanos as u32) -}