From 205336bf2e604b6283334bed230404f797c8ec19 Mon Sep 17 00:00:00 2001 From: Jonathan Schuster Date: Sun, 21 Feb 2016 13:08:20 -0500 Subject: [PATCH] Move util::range into its own crate --- components/gfx/Cargo.toml | 3 +++ components/gfx/display_list/mod.rs | 2 +- components/gfx/lib.rs | 3 ++- components/gfx/paint_context.rs | 2 +- components/gfx/text/glyph.rs | 2 +- components/gfx/text/shaping/harfbuzz.rs | 2 +- components/gfx/text/text_run.rs | 2 +- components/layout/Cargo.toml | 3 +++ components/layout/display_list_builder.rs | 2 +- components/layout/fragment.rs | 2 +- components/layout/inline.rs | 2 +- components/layout/lib.rs | 3 ++- components/layout/text.rs | 2 +- components/range/Cargo.toml | 17 +++++++++++++++ components/{util/range.rs => range/lib.rs} | 24 ++++++++++++++++------ components/servo/Cargo.lock | 15 +++++++++++++- components/util/Cargo.toml | 1 - components/util/lib.rs | 4 ---- ports/cef/Cargo.lock | 15 +++++++++++++- ports/geckolib/Cargo.lock | 1 - ports/gonk/Cargo.lock | 15 +++++++++++++- 21 files changed, 96 insertions(+), 26 deletions(-) create mode 100644 components/range/Cargo.toml rename components/{util/range.rs => range/lib.rs} (94%) diff --git a/components/gfx/Cargo.toml b/components/gfx/Cargo.toml index dc938835335..bc4b26de28e 100644 --- a/components/gfx/Cargo.toml +++ b/components/gfx/Cargo.toml @@ -52,6 +52,9 @@ path = "../msg" [dependencies.profile_traits] path = "../profile_traits" +[dependencies.range] +path = "../range" + [dependencies.style] path = "../style" diff --git a/components/gfx/display_list/mod.rs b/components/gfx/display_list/mod.rs index 5b0e3935904..763adb9d71a 100644 --- a/components/gfx/display_list/mod.rs +++ b/components/gfx/display_list/mod.rs @@ -27,6 +27,7 @@ use msg::constellation_msg::PipelineId; use net_traits::image::base::Image; use paint_context::PaintContext; use paint_thread::{PaintLayerContents, PaintLayer}; +use range::Range; use self::DisplayItem::*; use smallvec::SmallVec; use std::cmp::Ordering; @@ -44,7 +45,6 @@ use util::geometry::MAX_RECT; use util::linked_list::prepend_from; use util::opts; use util::print_tree::PrintTree; -use util::range::Range; use webrender_traits::WebGLContextId; pub use style::dom::OpaqueNode; diff --git a/components/gfx/lib.rs b/components/gfx/lib.rs index cb2576dba5c..74db34a03d3 100644 --- a/components/gfx/lib.rs +++ b/components/gfx/lib.rs @@ -59,6 +59,8 @@ extern crate net_traits; #[macro_use] extern crate profile_traits; extern crate rand; +#[macro_use] +extern crate range; extern crate rustc_serialize; extern crate serde; @@ -73,7 +75,6 @@ extern crate style_traits; extern crate time; extern crate unicode_script; extern crate url; -#[macro_use] extern crate util; extern crate webrender_traits; diff --git a/components/gfx/paint_context.rs b/components/gfx/paint_context.rs index 1270071825d..e020336429d 100644 --- a/components/gfx/paint_context.rs +++ b/components/gfx/paint_context.rs @@ -28,6 +28,7 @@ use filters; use font_context::FontContext; use gfx_traits::{color, LayerKind}; use net_traits::image::base::{Image, PixelFormat}; +use range::Range; use std::default::Default; use std::sync::Arc; use std::{f32, mem, ptr}; @@ -36,7 +37,6 @@ use text::TextRun; use text::glyph::CharIndex; use util::geometry::{self, MAX_RECT, PagePx, ScreenPx}; use util::opts; -use util::range::Range; pub struct PaintContext<'a> { pub draw_target: DrawTarget, diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index c1751742937..d480ffeb840 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -4,12 +4,12 @@ use app_units::Au; use euclid::point::Point2D; +use range::{self, EachIndex, Range, RangeIndex}; #[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))] use simd::u32x4; use std::cmp::{Ordering, PartialOrd}; use std::vec::Vec; use std::{fmt, mem, u16}; -use util::range::{self, EachIndex, Range, RangeIndex}; use util::vec::*; /// GlyphEntry is a port of Gecko's CompressedGlyph scheme for storing glyph data compactly. diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index 47d6756d346..495b6af6525 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -34,11 +34,11 @@ use harfbuzz::{hb_glyph_position_t}; use harfbuzz::{hb_position_t, hb_tag_t}; use libc::{c_char, c_int, c_uint, c_void}; use platform::font::FontTable; +use range::Range; use std::{char, cmp, ptr}; use text::glyph::{CharIndex, GlyphData, GlyphId, GlyphStore}; use text::shaping::ShaperMethods; use text::util::{fixed_to_float, float_to_fixed, is_bidi_control}; -use util::range::Range; macro_rules! hb_tag { ($t1:expr, $t2:expr, $t3:expr, $t4:expr) => ( diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 5a3d086de7e..182c5f836ea 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -6,12 +6,12 @@ use app_units::Au; use font::{Font, FontHandleMethods, FontMetrics, IS_WHITESPACE_SHAPING_FLAG, RunMetrics}; use font::{ShapingOptions}; use platform::font_template::FontTemplateData; +use range::Range; use std::cell::Cell; use std::cmp::{Ordering, max}; use std::slice::Iter; use std::sync::Arc; use text::glyph::{CharIndex, GlyphStore}; -use util::range::Range; use util::vec::{Comparator, FullBinarySearchMethods}; use webrender_traits; diff --git a/components/layout/Cargo.toml b/components/layout/Cargo.toml index 6658b5d1612..44cb976afe4 100644 --- a/components/layout/Cargo.toml +++ b/components/layout/Cargo.toml @@ -32,6 +32,9 @@ path = "../script" [dependencies.layout_traits] path = "../layout_traits" +[dependencies.range] +path = "../range" + [dependencies.script_traits] path = "../script_traits" diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index efd7b0a2394..8d5e5c48ed0 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -38,6 +38,7 @@ use list_item::ListItemFlow; use model::{self, MaybeAuto, ToGfxMatrix}; use net_traits::image::base::{Image, PixelFormat}; use net_traits::image_cache_thread::UsePlaceholder; +use range::Range; use std::default::Default; use std::sync::Arc; use std::{cmp, f32}; @@ -57,7 +58,6 @@ use style_traits::cursor::Cursor; use table_cell::CollapsedBordersForCell; use url::Url; use util::opts; -use util::range::Range; /// The logical width of an insertion point: at the moment, a one-pixel-wide line. const INSERTION_POINT_LOGICAL_WIDTH: Au = Au(1 * AU_PER_PX); diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 2c0fc922cb5..9239ee8a368 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -27,6 +27,7 @@ use model::{self, IntrinsicISizes, IntrinsicISizesContribution, MaybeAuto, speci use msg::constellation_msg::PipelineId; use net_traits::image::base::{Image, ImageMetadata}; use net_traits::image_cache_thread::{ImageOrMetadataAvailable, UsePlaceholder}; +use range::*; use rustc_serialize::{Encodable, Encoder}; use script::dom::htmlcanvaselement::HTMLCanvasData; use std::borrow::ToOwned; @@ -48,7 +49,6 @@ use text; use text::TextRunScanner; use url::Url; use util; -use util::range::*; use util::str::slice_chars; use wrapper::{PseudoElementType, ThreadSafeLayoutElement, ThreadSafeLayoutNode}; diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 3e3e6506cb7..bac7f3e07b9 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -21,6 +21,7 @@ use gfx::font_context::FontContext; use incremental::{BUBBLE_ISIZES, REFLOW, REFLOW_OUT_OF_FLOW, REPAINT, RESOLVE_GENERATED_CONTENT}; use layout_debug; use model::IntrinsicISizesContribution; +use range::{Range, RangeIndex}; use std::cmp::max; use std::collections::VecDeque; use std::sync::Arc; @@ -34,7 +35,6 @@ use text; use unicode_bidi; use util; use util::print_tree::PrintTree; -use util::range::{Range, RangeIndex}; use wrapper::PseudoElementType; // From gfxFontConstants.h in Firefox diff --git a/components/layout/lib.rs b/components/layout/lib.rs index 45366f7b669..2891e1cdae7 100644 --- a/components/layout/lib.rs +++ b/components/layout/lib.rs @@ -43,6 +43,8 @@ extern crate net_traits; extern crate plugins as servo_plugins; #[macro_use] extern crate profile_traits; +#[macro_use] +extern crate range; extern crate rustc_serialize; extern crate script; extern crate script_traits; @@ -57,7 +59,6 @@ extern crate time; extern crate unicode_bidi; extern crate unicode_script; extern crate url; -#[macro_use] extern crate util; extern crate webrender_traits; diff --git a/components/layout/text.rs b/components/layout/text.rs index 3a0506d05b3..2a9e99d18d3 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -15,6 +15,7 @@ use gfx::text::glyph::CharIndex; use gfx::text::text_run::TextRun; use gfx::text::util::{self, CompressionMode}; use inline::InlineFragments; +use range::{Range, RangeIndex}; use std::borrow::ToOwned; use std::collections::LinkedList; use std::mem; @@ -27,7 +28,6 @@ use style::properties::style_structs::Font as FontStyle; use unicode_bidi::{is_rtl, process_text}; use unicode_script::{get_script, Script}; use util::linked_list::split_off_head; -use util::range::{Range, RangeIndex}; /// Returns the concatenated text of a list of unscanned text fragments. fn text(fragments: &LinkedList) -> String { diff --git a/components/range/Cargo.toml b/components/range/Cargo.toml new file mode 100644 index 00000000000..6064280502a --- /dev/null +++ b/components/range/Cargo.toml @@ -0,0 +1,17 @@ +[package] + +name = "range" +version = "0.0.1" +authors = ["The Servo Project Developers"] + +[lib] +name = "range" +path = "lib.rs" + +[dependencies] +heapsize = "0.3.0" +heapsize_plugin = "0.1.2" +num = "0.1.24" +rustc-serialize = "0.3" +serde = "0.6" +serde_macros = "0.6" diff --git a/components/util/range.rs b/components/range/lib.rs similarity index 94% rename from components/util/range.rs rename to components/range/lib.rs index 8149a1f424c..1d006370149 100644 --- a/components/util/range.rs +++ b/components/range/lib.rs @@ -2,7 +2,19 @@ * 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 num_lib; +#![feature(custom_derive)] +#![feature(plugin)] +#![feature(step_trait)] +#![feature(zero_one)] + +#![plugin(heapsize_plugin)] +#![plugin(serde_macros)] + +extern crate heapsize; +extern crate num as num_lib; +extern crate rustc_serialize; +extern crate serde; + use std::cmp::{self, max, min}; use std::fmt; use std::iter; @@ -95,15 +107,15 @@ macro_rules! int_range_index { } } - impl $crate::range::Int for $Self_ { + impl $crate::Int for $Self_ { #[inline] - fn zero() -> $Self_ { $Self_($crate::range::Int::zero()) } + fn zero() -> $Self_ { $Self_($crate::Int::zero()) } #[inline] - fn one() -> $Self_ { $Self_($crate::range::Int::one()) } + fn one() -> $Self_ { $Self_($crate::Int::one()) } #[inline] - fn max_value() -> $Self_ { $Self_($crate::range::Int::max_value()) } + fn max_value() -> $Self_ { $Self_($crate::Int::max_value()) } #[inline] - fn from_usize(n: usize) -> Option<$Self_> { $crate::range::Int::from_usize(n).map($Self_) } + fn from_usize(n: usize) -> Option<$Self_> { $crate::Int::from_usize(n).map($Self_) } } impl ::std::ops::Add<$Self_> for $Self_ { diff --git a/components/servo/Cargo.lock b/components/servo/Cargo.lock index 23a93b6e0f4..aaa2fb4ef3b 100644 --- a/components/servo/Cargo.lock +++ b/components/servo/Cargo.lock @@ -676,6 +676,7 @@ dependencies = [ "plugins 0.0.1", "profile_traits 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1017,6 +1018,7 @@ dependencies = [ "net_traits 0.0.1", "plugins 0.0.1", "profile_traits 0.0.1", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", @@ -1560,6 +1562,18 @@ dependencies = [ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "range" +version = "0.0.1" +dependencies = [ + "heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize_plugin 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ref_slice" version = "0.1.0" @@ -2104,7 +2118,6 @@ dependencies = [ "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/components/util/Cargo.toml b/components/util/Cargo.toml index 555509d23ef..88e558a0ba4 100644 --- a/components/util/Cargo.toml +++ b/components/util/Cargo.toml @@ -38,7 +38,6 @@ heapsize_plugin = "0.1.2" lazy_static = "0.1" libc = "0.2" log = "0.3" -num = "0.1.24" num_cpus = "0.2.2" rand = "0.3" rustc-serialize = "0.3" diff --git a/components/util/lib.rs b/components/util/lib.rs index 881da2d5fd5..93cb5de4cc1 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -12,8 +12,6 @@ #![feature(plugin)] #![feature(reflect_marker)] #![feature(step_by)] -#![feature(step_trait)] -#![feature(zero_one)] #![plugin(heapsize_plugin, plugins, serde_macros)] @@ -35,7 +33,6 @@ extern crate lazy_static; extern crate libc; #[macro_use] extern crate log; -extern crate num as num_lib; extern crate num_cpus; extern crate rand; extern crate rustc_serialize; @@ -58,7 +55,6 @@ pub mod non_geckolib; pub mod opts; pub mod prefs; pub mod print_tree; -pub mod range; pub mod resource_files; pub mod str; pub mod thread; diff --git a/ports/cef/Cargo.lock b/ports/cef/Cargo.lock index d0ec8af8c64..9d88bbca99c 100644 --- a/ports/cef/Cargo.lock +++ b/ports/cef/Cargo.lock @@ -615,6 +615,7 @@ dependencies = [ "plugins 0.0.1", "profile_traits 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -947,6 +948,7 @@ dependencies = [ "net_traits 0.0.1", "plugins 0.0.1", "profile_traits 0.0.1", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", @@ -1446,6 +1448,18 @@ dependencies = [ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "range" +version = "0.0.1" +dependencies = [ + "heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize_plugin 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ref_slice" version = "0.1.0" @@ -2001,7 +2015,6 @@ dependencies = [ "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/geckolib/Cargo.lock b/ports/geckolib/Cargo.lock index a1f5a87933c..ac605556934 100644 --- a/ports/geckolib/Cargo.lock +++ b/ports/geckolib/Cargo.lock @@ -541,7 +541,6 @@ dependencies = [ "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/ports/gonk/Cargo.lock b/ports/gonk/Cargo.lock index f8dffe9ed2b..149cb0d3fba 100644 --- a/ports/gonk/Cargo.lock +++ b/ports/gonk/Cargo.lock @@ -617,6 +617,7 @@ dependencies = [ "plugins 0.0.1", "profile_traits 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", @@ -928,6 +929,7 @@ dependencies = [ "net_traits 0.0.1", "plugins 0.0.1", "profile_traits 0.0.1", + "range 0.0.1", "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", "script 0.0.1", "script_traits 0.0.1", @@ -1427,6 +1429,18 @@ dependencies = [ "winapi 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "range" +version = "0.0.1" +dependencies = [ + "heapsize 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "heapsize_plugin 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-serialize 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 0.6.15 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_macros 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ref_slice" version = "0.1.0" @@ -1980,7 +1994,6 @@ dependencies = [ "lazy_static 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "num 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "plugins 0.0.1", "rand 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)",