From 524966e3af8fbc871005cef460dc86c379a36034 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 22 Jan 2015 13:25:07 +0100 Subject: [PATCH 1/5] Use std::cmp::Ordering explicitly. --- components/gfx/text/glyph.rs | 6 ++-- components/gfx/text/text_run.rs | 7 +++-- components/style/selector_matching.rs | 3 +- components/util/sort.rs | 10 ++++--- components/util/time.rs | 5 ++-- components/util/vec.rs | 8 ++--- ports/cef/string.rs | 43 ++++++++++++++------------- 7 files changed, 44 insertions(+), 38 deletions(-) diff --git a/components/gfx/text/glyph.rs b/components/gfx/text/glyph.rs index 06e16c04a79..312c0692847 100644 --- a/components/gfx/text/glyph.rs +++ b/components/gfx/text/glyph.rs @@ -7,7 +7,7 @@ use servo_util::range; use servo_util::range::{Range, RangeIndex, EachIndex}; use servo_util::geometry::Au; -use std::cmp::PartialOrd; +use std::cmp::{Ordering, PartialOrd}; use std::iter::repeat; use std::num::NumCast; use std::mem; @@ -398,9 +398,9 @@ impl<'a> DetailedGlyphStore { let mut mut_records : Vec = unsorted_records; mut_records.sort_by(|a, b| { if a < b { - Less + Ordering::Less } else { - Greater + Ordering::Greater } }); let mut sorted_records = mut_records; diff --git a/components/gfx/text/text_run.rs b/components/gfx/text/text_run.rs index 8b8230a94cc..da5b6f3435e 100644 --- a/components/gfx/text/text_run.rs +++ b/components/gfx/text/text_run.rs @@ -8,6 +8,7 @@ use platform::font_template::FontTemplateData; use servo_util::geometry::Au; use servo_util::range::Range; use servo_util::vec::{Comparator, FullBinarySearchMethods}; +use std::cmp::Ordering; use std::slice::Items; use std::sync::Arc; use text::glyph::{CharIndex, GlyphStore}; @@ -42,11 +43,11 @@ struct CharIndexComparator; impl Comparator for CharIndexComparator { fn compare(&self, key: &CharIndex, value: &GlyphRun) -> Ordering { if *key < value.range.begin() { - Less + Ordering::Less } else if *key >= value.range.end() { - Greater + Ordering::Greater } else { - Equal + Ordering::Equal } } } diff --git a/components/style/selector_matching.rs b/components/style/selector_matching.rs index dba0294baec..c617b58e7f2 100644 --- a/components/style/selector_matching.rs +++ b/components/style/selector_matching.rs @@ -1161,6 +1161,7 @@ impl FindPush for HashMap> { #[cfg(test)] mod tests { + use std::cmp::Ordering; use std::sync::Arc; use super::{DeclarationBlock, Rule, SelectorMap}; use selectors::LocalName; @@ -1201,7 +1202,7 @@ mod tests { let rules_list = get_mock_rules(&["a.intro", "img.sidebar"]); let a = &rules_list[0][0].declarations; let b = &rules_list[1][0].declarations; - assert!((a.specificity, a.source_order).cmp(&(b.specificity, b.source_order)) == Less, + assert!((a.specificity, a.source_order).cmp(&(b.specificity, b.source_order)) == Ordering::Less, "The rule that comes later should win."); } diff --git a/components/util/sort.rs b/components/util/sort.rs index 73a244f713f..d31948cb0e8 100644 --- a/components/util/sort.rs +++ b/components/util/sort.rs @@ -4,6 +4,8 @@ //! In-place sorting. +use std::cmp::Ordering; + fn quicksort_helper(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) -> Ordering) { if right <= left { return @@ -17,11 +19,11 @@ fn quicksort_helper(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) let v: *mut T = &mut arr[right as uint]; loop { i += 1; - while compare(&arr[i as uint], &*v) == Less { + while compare(&arr[i as uint], &*v) == Ordering::Less { i += 1 } j -= 1; - while compare(&*v, &arr[j as uint]) == Less { + while compare(&*v, &arr[j as uint]) == Ordering::Less { if j == left { break } @@ -31,11 +33,11 @@ fn quicksort_helper(arr: &mut [T], left: int, right: int, compare: fn(&T, &T) break } arr.swap(i as uint, j as uint); - if compare(&arr[i as uint], &*v) == Equal { + if compare(&arr[i as uint], &*v) == Ordering::Equal { p += 1; arr.swap(p as uint, i as uint) } - if compare(&*v, &arr[j as uint]) == Equal { + if compare(&*v, &arr[j as uint]) == Ordering::Equal { q -= 1; arr.swap(j as uint, q as uint) } diff --git a/components/util/time.rs b/components/util/time.rs index abe35633e92..a47f3a98c8c 100644 --- a/components/util/time.rs +++ b/components/util/time.rs @@ -6,6 +6,7 @@ use collections::TreeMap; use std::borrow::ToOwned; +use std::cmp::Ordering; use std::comm::{Sender, channel, Receiver}; use std::f64; use std::io::timer::sleep; @@ -228,9 +229,9 @@ impl TimeProfiler { for (&(ref category, ref meta), ref mut data) in self.buckets.iter_mut() { data.sort_by(|a, b| { if a < b { - Less + Ordering::Less } else { - Greater + Ordering::Greater } }); let data_len = data.len(); diff --git a/components/util/vec.rs b/components/util/vec.rs index b9a67b6760b..c34b76a9794 100644 --- a/components/util/vec.rs +++ b/components/util/vec.rs @@ -2,7 +2,7 @@ * 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::cmp::{PartialOrd, PartialEq}; +use std::cmp::{PartialOrd, PartialEq, Ordering}; #[cfg(test)] use std::fmt::Show; @@ -47,9 +47,9 @@ impl<'a, T> FullBinarySearchMethods for &'a [T] { let midv = &self[mid]; match cmp.compare(key, midv) { - Greater => low = (mid as int) + 1, - Less => high = (mid as int) - 1, - Equal => return Some(mid), + Ordering::Greater => low = (mid as int) + 1, + Ordering::Less => high = (mid as int) - 1, + Ordering::Equal => return Some(mid), } } return None; diff --git a/ports/cef/string.rs b/ports/cef/string.rs index d0a0e4ba4e3..a396eabff69 100644 --- a/ports/cef/string.rs +++ b/ports/cef/string.rs @@ -7,6 +7,7 @@ use eutil::slice_to_str; use libc::{mod, size_t, c_int, c_ushort, c_void}; use libc::types::os::arch::c95::wchar_t; use std::char; +use std::cmp::Ordering; use std::mem; use std::ptr; use std::slice; @@ -106,15 +107,15 @@ pub extern "C" fn cef_string_utf8_set(src: *const u8, src_len: size_t, output: * #[no_mangle] pub extern "C" fn cef_string_utf8_cmp(a: *const cef_string_utf8_t, b: *const cef_string_utf8_t) -> c_int { unsafe { - slice::raw::buf_as_slice((*a).str as *const u8, (*a).length as uint, |astr:&[u8]| { + slice::raw::buf_as_slice((*a).str as *const u8, (*a).length as uint, |astr:&[u8]| { slice::raw::buf_as_slice((*b).str as *const u8, (*b).length as uint, |bstr:&[u8]| { - match astr.cmp(bstr) { - Less => -1, - Equal => 0, - Greater => 1 - } + match astr.cmp(bstr) { + Ordering::Less => -1, + Ordering::Equal => 0, + Ordering::Greater => 1 + } }) - }) + }) } } @@ -188,15 +189,15 @@ pub extern "C" fn cef_string_utf16_set(src: *const c_ushort, src_len: size_t, ou #[no_mangle] pub extern "C" fn cef_string_utf16_cmp(a: *const cef_string_utf16_t, b: *const cef_string_utf16_t) -> c_int { unsafe { - slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| { + slice::raw::buf_as_slice(mem::transmute((*a).str), (*a).length as uint, |astr:&[u16]| { slice::raw::buf_as_slice(mem::transmute((*b).str), (*b).length as uint, |bstr:&[u16]| { - match astr.cmp(bstr) { - Less => -1, - Equal => 0, - Greater => 1 - } + match astr.cmp(bstr) { + Ordering::Less => -1, + Ordering::Equal => 0, + Ordering::Greater => 1 + } }) - }) + }) } } @@ -246,15 +247,15 @@ pub extern "C" fn cef_string_wide_set(src: *const wchar_t, src_len: size_t, outp #[no_mangle] pub extern "C" fn cef_string_wide_cmp(a: *const cef_string_wide_t, b: *const cef_string_wide_t) -> c_int { unsafe { - slice::raw::buf_as_slice((*a).str as *const wchar_t, (*a).length as uint, |astr:&[wchar_t]| { + slice::raw::buf_as_slice((*a).str as *const wchar_t, (*a).length as uint, |astr:&[wchar_t]| { slice::raw::buf_as_slice((*b).str as *const wchar_t, (*b).length as uint, |bstr:&[wchar_t]| { - match astr.cmp(bstr) { - Less => -1, - Equal => 0, - Greater => 1 - } + match astr.cmp(bstr) { + Ordering::Less => -1, + Ordering::Equal => 0, + Ordering::Greater => 1 + } }) - }) + }) } } From faefb27f3e8daed229bc8f15956e314fc01e31d9 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 22 Jan 2015 13:25:20 +0100 Subject: [PATCH 2/5] Use std::sync::atomic::Ordering explicitly. --- components/layout/construct.rs | 4 ++-- components/layout/flow.rs | 6 +++--- components/layout/flow_ref.rs | 6 +++--- components/layout/layout_debug.rs | 4 ++-- components/layout/parallel.rs | 10 +++++----- components/util/tid.rs | 4 ++-- components/util/workqueue.rs | 6 +++--- ports/cef/browser.rs | 4 ++-- 8 files changed, 22 insertions(+), 22 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index 742fb2ebb3e..a13d815984d 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -53,7 +53,7 @@ use servo_util::opts; use std::borrow::ToOwned; use std::collections::DList; use std::mem; -use std::sync::atomic::Relaxed; +use std::sync::atomic::Ordering; use style::computed_values::{caption_side, display, empty_cells, float, list_style_position}; use style::computed_values::{position}; use style::{mod, ComputedValues}; @@ -1385,7 +1385,7 @@ impl FlowConstructionUtils for FlowRef { } base.children.push_back(new_child); - let _ = base.parallel.children_count.fetch_add(1, Relaxed); + let _ = base.parallel.children_count.fetch_add(1, Ordering::Relaxed); } /// Finishes a flow. Once a flow is finished, no more child flows or fragments may be added to diff --git a/components/layout/flow.rs b/components/layout/flow.rs index bbfb698a2f3..8c7588f0666 100644 --- a/components/layout/flow.rs +++ b/components/layout/flow.rs @@ -56,7 +56,7 @@ use std::mem; use std::fmt; use std::iter::Zip; use std::raw; -use std::sync::atomic::{AtomicUint, SeqCst}; +use std::sync::atomic::{AtomicUint, Ordering}; use std::slice::MutItems; use style::computed_values::{clear, empty_cells, float, position, text_align}; use style::ComputedValues; @@ -781,7 +781,7 @@ impl fmt::Show for BaseFlow { write!(f, "@ {}, CC {}, ADC {}", self.position, - self.parallel.children_count.load(SeqCst), + self.parallel.children_count.load(Ordering::SeqCst), self.abs_descendants.len()) } } @@ -830,7 +830,7 @@ impl> Encodable for BaseFlow { #[unsafe_destructor] impl Drop for BaseFlow { fn drop(&mut self) { - if self.ref_count.load(SeqCst) != 0 { + if self.ref_count.load(Ordering::SeqCst) != 0 { panic!("Flow destroyed before its ref count hit zero—this is unsafe!") } } diff --git a/components/layout/flow_ref.rs b/components/layout/flow_ref.rs index 67f306d4508..5e4d0a37563 100644 --- a/components/layout/flow_ref.rs +++ b/components/layout/flow_ref.rs @@ -12,7 +12,7 @@ use flow; use std::mem; use std::ptr; use std::raw; -use std::sync::atomic::SeqCst; +use std::sync::atomic::Ordering; #[unsafe_no_drop_flag] pub struct FlowRef { @@ -55,7 +55,7 @@ impl Drop for FlowRef { if self.object.vtable.is_null() { return } - if flow::base(&**self).ref_count().fetch_sub(1, SeqCst) > 1 { + if flow::base(&**self).ref_count().fetch_sub(1, Ordering::SeqCst) > 1 { return } let flow_ref: FlowRef = mem::replace(self, FlowRef { @@ -75,7 +75,7 @@ impl Drop for FlowRef { impl Clone for FlowRef { fn clone(&self) -> FlowRef { unsafe { - drop(flow::base(self.deref()).ref_count().fetch_add(1, SeqCst)); + drop(flow::base(self.deref()).ref_count().fetch_add(1, Ordering::SeqCst)); FlowRef { object: raw::TraitObject { vtable: self.object.vtable, diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index 3b28362f326..aae0503d1eb 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -14,7 +14,7 @@ use serialize::json; use std::borrow::ToOwned; use std::cell::RefCell; use std::io::File; -use std::sync::atomic::{AtomicUint, SeqCst, INIT_ATOMIC_UINT}; +use std::sync::atomic::{AtomicUint, Ordering, INIT_ATOMIC_UINT}; thread_local!(static STATE_KEY: RefCell> = RefCell::new(None)) @@ -96,7 +96,7 @@ impl Drop for Scope { /// which are often reallocated but represent essentially the /// same data. pub fn generate_unique_debug_id() -> u16 { - unsafe { DEBUG_ID_COUNTER.fetch_add(1, SeqCst) as u16 } + unsafe { DEBUG_ID_COUNTER.fetch_add(1, Ordering::SeqCst) as u16 } } /// Begin a layout debug trace. If this has not been called, diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index a6a20ad33ba..5ec5c2c661b 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -23,7 +23,7 @@ use servo_util::time::{TimeProfilerCategory, ProfilerMetadata, TimeProfilerChan, use servo_util::workqueue::{WorkQueue, WorkUnit, WorkerProxy}; use std::mem; use std::ptr; -use std::sync::atomic::{AtomicInt, Relaxed, SeqCst}; +use std::sync::atomic::{AtomicInt, Ordering}; #[allow(dead_code)] fn static_assertion(node: UnsafeLayoutNode) { @@ -108,7 +108,7 @@ pub trait ParallelPreorderDomTraversal : PreorderDomTraversal { { let mut layout_data_ref = node.mutate_layout_data(); let layout_data = layout_data_ref.as_mut().expect("no layout data"); - layout_data.data.parallel.children_count.store(child_count as int, Relaxed); + layout_data.data.parallel.children_count.store(child_count as int, Ordering::Relaxed); } // Possibly enqueue the children. @@ -173,7 +173,7 @@ trait ParallelPostorderDomTraversal : PostorderDomTraversal { .data .parallel .children_count - .fetch_sub(1, SeqCst) == 1 { + .fetch_sub(1, Ordering::SeqCst) == 1 { // We were the last child of our parent. Construct flows for our parent. } else { // Get out of here and find another node to work on. @@ -231,7 +231,7 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal { let base = flow::mut_base(flow.deref_mut()); // Reset the count of children for the next layout traversal. - base.parallel.children_count.store(base.children.len() as int, Relaxed); + base.parallel.children_count.store(base.children.len() as int, Ordering::Relaxed); // Possibly enqueue the parent. let unsafe_parent = base.parallel.parent; @@ -245,7 +245,7 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal { // on with our parent; otherwise, we've gotta wait. let parent: &mut FlowRef = mem::transmute(&unsafe_parent); let parent_base = flow::mut_base(parent.deref_mut()); - if parent_base.parallel.children_count.fetch_sub(1, SeqCst) == 1 { + if parent_base.parallel.children_count.fetch_sub(1, Ordering::SeqCst) == 1 { // We were the last child of our parent. Reflow our parent. unsafe_flow = unsafe_parent } else { diff --git a/components/util/tid.rs b/components/util/tid.rs index 5cea4fe0d43..62723941fcb 100644 --- a/components/util/tid.rs +++ b/components/util/tid.rs @@ -2,7 +2,7 @@ * 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::sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, SeqCst}; +use std::sync::atomic::{AtomicUint, INIT_ATOMIC_UINT, Ordering}; use std::rc::Rc; use std::cell::RefCell; @@ -15,7 +15,7 @@ pub fn tid() -> uint { TASK_LOCAL_TID.with(|ref k| { let ret = match *k.borrow() { - None => unsafe { next_tid.fetch_add(1, SeqCst) }, + None => unsafe { next_tid.fetch_add(1, Ordering::SeqCst) }, Some(x) => x, }; diff --git a/components/util/workqueue.rs b/components/util/workqueue.rs index 9fef7ac2a81..ee14a4d1a50 100644 --- a/components/util/workqueue.rs +++ b/components/util/workqueue.rs @@ -14,7 +14,7 @@ use libc::funcs::posix88::unistd::usleep; use rand::{Rng, XorShiftRng}; use std::mem; use std::rand::weak_rng; -use std::sync::atomic::{AtomicUint, SeqCst}; +use std::sync::atomic::{AtomicUint, Ordering}; use deque::{Abort, BufferPool, Data, Empty, Stealer, Worker}; /// A unit of work. @@ -157,7 +157,7 @@ impl WorkerThread { // The work is done. Now decrement the count of outstanding work items. If this was // the last work unit in the queue, then send a message on the channel. unsafe { - if (*ref_count).fetch_sub(1, SeqCst) == 1 { + if (*ref_count).fetch_sub(1, Ordering::SeqCst) == 1 { self.chan.send(SupervisorMsg::Finished) } } @@ -181,7 +181,7 @@ impl<'a, QueueData: 'static, WorkData: Send> WorkerProxy<'a, QueueData, WorkData #[inline] pub fn push(&mut self, work_unit: WorkUnit) { unsafe { - drop((*self.ref_count).fetch_add(1, SeqCst)); + drop((*self.ref_count).fetch_add(1, Ordering::SeqCst)); } self.worker.push(work_unit); } diff --git a/ports/cef/browser.rs b/ports/cef/browser.rs index 9a6aa48a35d..af7607ced73 100644 --- a/ports/cef/browser.rs +++ b/ports/cef/browser.rs @@ -18,7 +18,7 @@ use libc::c_int; use servo_util::opts; use std::borrow::ToOwned; use std::cell::{Cell, RefCell}; -use std::sync::atomic::{AtomicInt, SeqCst}; +use std::sync::atomic::{AtomicInt, Ordering}; thread_local!(pub static ID_COUNTER: AtomicInt = AtomicInt::new(0)) thread_local!(pub static BROWSERS: RefCell> = RefCell::new(vec!())) @@ -105,7 +105,7 @@ impl ServoCefBrowser { }; let id = ID_COUNTER.with(|counter| { - counter.fetch_add(1, SeqCst) + counter.fetch_add(1, Ordering::SeqCst) }); ServoCefBrowser { From 024571dfa38dbe63cb2a591571e2465b5d882686 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 22 Jan 2015 13:49:10 +0100 Subject: [PATCH 3/5] Use chars().count() rather than char_len(). The latter is obsolete in current Rust. --- components/gfx/font.rs | 2 +- components/gfx/text/shaping/harfbuzz.rs | 2 +- components/layout/text.rs | 4 ++-- components/script/dom/htmlinputelement.rs | 2 +- components/script/textinput.rs | 8 ++++---- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/components/gfx/font.rs b/components/gfx/font.rs index 708a6f4b93d..653eff5e5f3 100644 --- a/components/gfx/font.rs +++ b/components/gfx/font.rs @@ -157,7 +157,7 @@ impl Font { Some(glyphs) => return (*glyphs).clone(), } - let mut glyphs = GlyphStore::new(text.char_len() as int, + let mut glyphs = GlyphStore::new(text.chars().count() as int, options.flags.contains(IS_WHITESPACE_SHAPING_FLAG)); shaper.as_ref().unwrap().shape_text(text, options, &mut glyphs); diff --git a/components/gfx/text/shaping/harfbuzz.rs b/components/gfx/text/shaping/harfbuzz.rs index e02f15bdc45..98b287ba086 100644 --- a/components/gfx/text/shaping/harfbuzz.rs +++ b/components/gfx/text/shaping/harfbuzz.rs @@ -274,7 +274,7 @@ impl Shaper { let glyph_data = ShapedGlyphData::new(buffer); let glyph_count = glyph_data.len(); let byte_max = text.len() as int; - let char_max = text.char_len() as int; + let char_max = text.chars().count() as int; // GlyphStore records are indexed by character, not byte offset. // so, we must be careful to increment this when saving glyph entries. diff --git a/components/layout/text.rs b/components/layout/text.rs index f57aee50f7b..324604281b4 100644 --- a/components/layout/text.rs +++ b/components/layout/text.rs @@ -138,7 +138,7 @@ impl TextRunScanner { }; let mut new_line_pos = Vec::new(); - let old_length = CharIndex(run_text.as_slice().char_len() as int); + let old_length = CharIndex(run_text.chars().count() as int); last_whitespace = util::transform_text(in_fragment.as_slice(), compression, last_whitespace, @@ -146,7 +146,7 @@ impl TextRunScanner { &mut new_line_pos); new_line_positions.push(NewLinePositions(new_line_pos)); - let added_chars = CharIndex(run_text.as_slice().char_len() as int) - old_length; + let added_chars = CharIndex(run_text.chars().count() as int) - old_length; new_ranges.push(Range::new(char_total, added_chars)); char_total = char_total + added_chars; } diff --git a/components/script/dom/htmlinputelement.rs b/components/script/dom/htmlinputelement.rs index 55f7a102ce3..507f6d05818 100644 --- a/components/script/dom/htmlinputelement.rs +++ b/components/script/dom/htmlinputelement.rs @@ -161,7 +161,7 @@ impl LayoutHTMLInputElementHelpers for JS { InputType::InputReset => get_raw_attr_value(self).unwrap_or_else(|| DEFAULT_RESET_VALUE.to_owned()), InputType::InputPassword => { let raw = get_raw_textinput_value(self); - String::from_char(raw.char_len(), '●') + raw.chars().map(|_| '●').collect() } _ => get_raw_textinput_value(self), } diff --git a/components/script/textinput.rs b/components/script/textinput.rs index c2c183d022c..4c4226738cf 100644 --- a/components/script/textinput.rs +++ b/components/script/textinput.rs @@ -135,7 +135,7 @@ impl TextInput { let new_lines = { let prefix = self.lines[begin.line].slice_chars(0, begin.index); - let suffix = self.lines[end.line].slice_chars(end.index, self.lines[end.line].char_len()); + let suffix = self.lines[end.line].slice_chars(end.index, self.lines[end.line].chars().count()); let lines_prefix = self.lines.slice(0, begin.line); let lines_suffix = self.lines.slice(end.line + 1, self.lines.len()); @@ -150,7 +150,7 @@ impl TextInput { insert_lines[0] = new_line; let last_insert_lines_index = insert_lines.len() - 1; - self.edit_point.index = insert_lines[last_insert_lines_index].char_len(); + self.edit_point.index = insert_lines[last_insert_lines_index].chars().count(); self.edit_point.line = begin.line + last_insert_lines_index; insert_lines[last_insert_lines_index].push_str(suffix); @@ -167,7 +167,7 @@ impl TextInput { /// Return the length of the current line under the editing point. fn current_line_length(&self) -> uint { - self.lines[self.edit_point.line].char_len() + self.lines[self.edit_point.line].chars().count() } /// Adjust the editing point position by a given of lines. The resulting column is @@ -260,7 +260,7 @@ impl TextInput { }); let last_line = self.lines.len() - 1; self.edit_point.line = last_line; - self.edit_point.index = self.lines[last_line].char_len(); + self.edit_point.index = self.lines[last_line].chars().count(); } /// Remove the current selection. From ee4c56bd8ba333ee8e4b21e0678d406a67a79b66 Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 22 Jan 2015 13:58:46 +0100 Subject: [PATCH 4/5] Remove rtinstrument (fixes #4600). The code has been disabled during the last rust upgrade, and has not found an owner. Since the next rust upgrade will bitrot it even more, it is better to remove it for now. If anyone wishes to restore it, the code remains in version history. --- components/servo/main.rs | 6 - components/util/lib.rs | 2 - components/util/rtinstrument.rs | 198 -------------------------------- components/util/task.rs | 18 +-- 4 files changed, 6 insertions(+), 218 deletions(-) delete mode 100644 components/util/rtinstrument.rs diff --git a/components/servo/main.rs b/components/servo/main.rs index afa1281d16b..f2fbf67dfb3 100644 --- a/components/servo/main.rs +++ b/components/servo/main.rs @@ -32,10 +32,6 @@ use libc::c_int; #[cfg(not(test))] use servo_util::opts; -// FIXME: Find replacement for this post-runtime removal -//#[cfg(not(test))] -//use servo_util::rtinstrument; - #[cfg(not(test))] use servo::Browser; #[cfg(not(test))] @@ -161,8 +157,6 @@ fn main() { browser } = browser; browser.shutdown(); - - //rtinstrument::teardown(); } } diff --git a/components/util/lib.rs b/components/util/lib.rs index d69bc982e17..524990368d5 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -51,8 +51,6 @@ pub mod opts; pub mod persistent_list; pub mod range; pub mod resource_files; -// FIXME: Find replacement for this post-runtime removal -// pub mod rtinstrument; pub mod smallvec; pub mod sort; pub mod str; diff --git a/components/util/rtinstrument.rs b/components/util/rtinstrument.rs deleted file mode 100644 index 2c3fca6bd3c..00000000000 --- a/components/util/rtinstrument.rs +++ /dev/null @@ -1,198 +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 opts; -use std::any::Any; -use std::borrow::ToOwned; -#[cfg(not(test))] -use std::io::File; -//use std::mem; -//use std::raw; -use std::rt::Runtime; -use std::rt::local::Local; -//use std::rt::rtio; -use std::rt::task::{Task, TaskOpts, BlockedTask}; -use std_time; -use std::sync::Mutex; -#[cfg(not(test))] -use serialize::json; - -#[deriving(Encodable)] -pub enum Event { - Spawn, - Schedule, - Unschedule, - Death, -} - -#[deriving(Encodable)] -pub struct Message { - timestamp: u64, - event: Event, -} - -#[deriving(Encodable)] -pub struct TaskStats { - pub name: String, - pub messages: Vec, - pub task_id: uint, -} - -struct InstrumentedRuntime { - inner: Option>, - messages: Vec, -} - -#[deriving(Encodable)] -pub struct GlobalState { - task_stats: Vec, -} - -#[cfg(not(test))] -pub fn teardown() { - if opts::get().profile_tasks { - let state = GLOBAL_STATE.lock(); - let result = json::encode(&*state); - let path = Path::new("thread_trace.json"); - let mut file = File::create(&path).unwrap(); - file.write_str(result.as_slice()).unwrap(); - } -} - -impl GlobalState { - fn new() -> GlobalState { - GlobalState { - task_stats: vec!(), - } - } -} - -lazy_static! { - pub static ref GLOBAL_STATE: Mutex = Mutex::new(GlobalState::new()); -} - -/// Instrument all code run inside the specific block, returning a vector of all -/// messages which occurred. -pub fn instrument(f: proc()) { - if opts::get().profile_tasks { - install(); - f(); - let rt = uninstall(); - let task_id = rt.task_id(); - let name = { - let task = Local::borrow(None::); - match task.name { - Some(ref name) => name.to_string(), - None => "unknown".to_owned(), - } - }; - let stats = TaskStats { - name: name, - messages: rt.messages, - task_id: task_id, - }; - let mut state = GLOBAL_STATE.lock(); - state.task_stats.push(stats); - } else { - f(); - } -} - -/// Installs an instrumented runtime which will append to the given vector of -/// messages. -/// -/// The instrumented runtime is installed into the current task. -fn install() { - let mut task = Local::borrow(None::); - let rt = task.take_runtime(); - let mut new_rt = box InstrumentedRuntime { - inner: Some(rt), - messages: vec!(), - }; - new_rt.log(Event::Spawn); - task.put_runtime(new_rt); -} - -/// Uninstalls the runtime from the current task, returning the instrumented -/// runtime. -fn uninstall() -> InstrumentedRuntime { - let mut task = Local::borrow(None::); - let mut rt = task.maybe_take_runtime::().unwrap(); - rt.log(Event::Death); - task.put_runtime(rt.inner.take().unwrap()); - *rt -} - -impl InstrumentedRuntime { - /// Puts this runtime back into the local task - fn put(mut self: Box, event: Option) { - assert!(self.inner.is_none()); - - let mut task: Box = Local::take(); - let rt = task.take_runtime(); - self.inner = Some(rt); - match event { - Some(event) => self.log(event), - None => {} - } - task.put_runtime(self); - Local::put(task); - } - - /// Logs a message into this runtime - fn log(&mut self, event: Event) { - self.messages.push(Message { - timestamp: std_time::precise_time_ns(), - event: event, - }); - } - - fn task_id(&self) -> uint { self as *const _ as uint } -} - -impl Runtime for InstrumentedRuntime { - fn stack_guard(&self) -> Option { - self.inner.as_ref().unwrap().stack_guard() - } - - fn yield_now(mut self: Box, cur_task: Box) { - self.inner.take().unwrap().yield_now(cur_task); - self.put(None) - } - - fn maybe_yield(mut self: Box, cur_task: Box) { - self.inner.take().unwrap().maybe_yield(cur_task); - self.put(None) - } - - fn deschedule(mut self: Box, times: uint, cur_task: Box, - f: |BlockedTask| -> Result<(), BlockedTask>) { - self.log(Event::Unschedule); - self.inner.take().unwrap().deschedule(times, cur_task, f); - self.put(Some(Event::Schedule)); - } - - fn reawaken(mut self: Box, to_wake: Box) { - self.inner.take().unwrap().reawaken(to_wake); - self.put(None); - } - - fn spawn_sibling(mut self: Box, - cur_task: Box, - opts: TaskOpts, - f: proc():Send) { - // Be sure to install an instrumented runtime for the spawned sibling by - // specifying a new runtime. - self.inner.take().unwrap().spawn_sibling(cur_task, opts, proc() { - install(); - f(); - drop(uninstall()); - }); - self.put(None) - } - - fn stack_bounds(&self) -> (uint, uint) { self.inner.as_ref().unwrap().stack_bounds() } - fn can_block(&self) -> bool { self.inner.as_ref().unwrap().can_block() } - fn wrap(self: Box) -> Box { self as Box } -} diff --git a/components/util/task.rs b/components/util/task.rs index fbfe13078b3..44c2ff284dc 100644 --- a/components/util/task.rs +++ b/components/util/task.rs @@ -6,13 +6,11 @@ use std::borrow::ToOwned; use std::task; use std::comm::Sender; use std::task::TaskBuilder; -// use rtinstrument; use task_state; pub fn spawn_named(name: String, f: proc():Send) { let builder = task::TaskBuilder::new().named(name); builder.spawn(proc() { - // rtinstrument::instrument(f); f(); }); } @@ -25,22 +23,18 @@ pub fn spawn_named_with_send_on_failure(name: &'static str, dest: Sender) { let future_result = TaskBuilder::new().named(name).try_future(proc() { task_state::initialize(state); - // FIXME: Find replacement for this post-runtime removal - // rtinstrument::instrument(f); f(); }); let watched_name = name.to_owned(); let watcher_name = format!("{}Watcher", watched_name); TaskBuilder::new().named(watcher_name).spawn(proc() { - //rtinstrument::instrument(proc() { - match future_result.into_inner() { - Ok(()) => (), - Err(..) => { - debug!("{} failed, notifying constellation", name); - dest.send(msg); - } + match future_result.into_inner() { + Ok(()) => (), + Err(..) => { + debug!("{} failed, notifying constellation", name); + dest.send(msg); } - //}); + } }); } From 13c7cf928a5817de315a58a4fa15dc9b7fdc3d7f Mon Sep 17 00:00:00 2001 From: Ms2ger Date: Thu, 22 Jan 2015 14:49:14 +0100 Subject: [PATCH 5/5] Stop calling deref() and deref_mut() explicitly. --- components/layout/construct.rs | 10 ++++---- components/layout/display_list_builder.rs | 6 ++--- components/layout/flow_list.rs | 12 +++++----- components/layout/flow_ref.rs | 2 +- components/layout/fragment.rs | 4 ++-- components/layout/inline.rs | 4 ++-- components/layout/layout_debug.rs | 8 +++---- components/layout/layout_task.rs | 29 +++++++++++------------ components/layout/parallel.rs | 16 ++++++------- components/layout/sequential.rs | 6 ++--- components/script/dom/bindings/js.rs | 2 +- components/script/dom/element.rs | 2 +- components/script/dom/node.rs | 8 +++---- components/util/lib.rs | 4 ++-- 14 files changed, 56 insertions(+), 57 deletions(-) diff --git a/components/layout/construct.rs b/components/layout/construct.rs index a13d815984d..9445eef9c04 100644 --- a/components/layout/construct.rs +++ b/components/layout/construct.rs @@ -90,7 +90,7 @@ impl ConstructionResult { match self { &ConstructionResult::None => 0u, &ConstructionResult::ConstructionItem(_) => 0u, - &ConstructionResult::Flow(ref flow_ref, _) => flow::base(flow_ref.deref()).debug_id(), + &ConstructionResult::Flow(ref flow_ref, _) => flow::base(&**flow_ref).debug_id(), } } } @@ -376,7 +376,7 @@ impl<'a> FlowConstructor<'a> { ConstructionResult::Flow(kid_flow, kid_abs_descendants) => { // If kid_flow is TableCaptionFlow, kid_flow should be added under // TableWrapperFlow. - if flow.is_table() && kid_flow.deref().is_table_caption() { + if flow.is_table() && kid_flow.is_table_caption() { kid.set_flow_construction_result(ConstructionResult::Flow(kid_flow, Descendants::new())) } else if flow.need_anonymous_flow(&*kid_flow) { @@ -815,7 +815,7 @@ impl<'a> FlowConstructor<'a> { for kid in node.children() { match kid.swap_out_construction_result() { ConstructionResult::Flow(mut kid_flow, _) => { - if kid_flow.deref().is_table_caption() && + if kid_flow.is_table_caption() && kid_flow.as_block() .fragment .style() @@ -1377,10 +1377,10 @@ impl FlowConstructionUtils for FlowRef { /// /// This must not be public because only the layout constructor can do this. fn add_new_child(&mut self, mut new_child: FlowRef) { - let base = flow::mut_base(self.deref_mut()); + let base = flow::mut_base(&mut **self); { - let kid_base = flow::mut_base(new_child.deref_mut()); + let kid_base = flow::mut_base(&mut *new_child); kid_base.parallel.parent = parallel::mut_owned_flow_to_unsafe_flow(self); } diff --git a/components/layout/display_list_builder.rs b/components/layout/display_list_builder.rs index b866ae2c2fd..73d0461e13d 100644 --- a/components/layout/display_list_builder.rs +++ b/components/layout/display_list_builder.rs @@ -879,7 +879,7 @@ impl FragmentDisplayListBuilding for Fragment { let (sender, receiver) = channel::>(); let canvas_data = match canvas_fragment_info.renderer { Some(ref renderer) => { - renderer.deref().lock().send(SendPixelContents(sender)); + renderer.lock().send(SendPixelContents(sender)); receiver.recv() }, None => repeat(0xFFu8).take(width * height * 4).collect(), @@ -1226,12 +1226,12 @@ impl InlineFlowDisplayListBuilding for InlineFlow { &self.base.clip); match fragment.specific { SpecificFragmentInfo::InlineBlock(ref mut block_flow) => { - let block_flow = block_flow.flow_ref.deref_mut(); + let block_flow = &mut *block_flow.flow_ref; flow::mut_base(block_flow).display_list_building_result .add_to(&mut *display_list) } SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut block_flow) => { - let block_flow = block_flow.flow_ref.deref_mut(); + let block_flow = &mut *block_flow.flow_ref; flow::mut_base(block_flow).display_list_building_result .add_to(&mut *display_list) } diff --git a/components/layout/flow_list.rs b/components/layout/flow_list.rs index c3300e6ab79..63522a06caa 100644 --- a/components/layout/flow_list.rs +++ b/components/layout/flow_list.rs @@ -26,25 +26,25 @@ impl FlowList { /// Provide a reference to the front element, or None if the list is empty #[inline] pub fn front<'a>(&'a self) -> Option<&'a Flow> { - self.flows.front().map(|head| head.deref()) + self.flows.front().map(|head| &**head) } /// Provide a mutable reference to the front element, or None if the list is empty #[inline] pub unsafe fn front_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { - self.flows.front_mut().map(|head| head.deref_mut()) + self.flows.front_mut().map(|head| &mut **head) } /// Provide a reference to the back element, or None if the list is empty #[inline] pub fn back<'a>(&'a self) -> Option<&'a Flow> { - self.flows.back().map(|tail| tail.deref()) + self.flows.back().map(|tail| &**tail) } /// Provide a mutable reference to the back element, or None if the list is empty #[inline] pub unsafe fn back_mut<'a>(&'a mut self) -> Option<&'a mut Flow> { - self.flows.back_mut().map(|tail| tail.deref_mut()) + self.flows.back_mut().map(|tail| &mut **tail) } /// Add an element first in the list @@ -108,7 +108,7 @@ impl FlowList { impl<'a> Iterator<&'a (Flow + 'a)> for FlowListIterator<'a> { #[inline] fn next(&mut self) -> Option<&'a (Flow + 'a)> { - self.it.next().map(|x| x.deref()) + self.it.next().map(|x| &**x) } #[inline] @@ -120,7 +120,7 @@ impl<'a> Iterator<&'a (Flow + 'a)> for FlowListIterator<'a> { impl<'a> Iterator<&'a mut (Flow + 'a)> for MutFlowListIterator<'a> { #[inline] fn next(&mut self) -> Option<&'a mut (Flow + 'a)> { - self.it.next().map(|x| x.deref_mut()) + self.it.next().map(|x| &mut **x) } #[inline] diff --git a/components/layout/flow_ref.rs b/components/layout/flow_ref.rs index 5e4d0a37563..7ee600919b0 100644 --- a/components/layout/flow_ref.rs +++ b/components/layout/flow_ref.rs @@ -75,7 +75,7 @@ impl Drop for FlowRef { impl Clone for FlowRef { fn clone(&self) -> FlowRef { unsafe { - drop(flow::base(self.deref()).ref_count().fetch_add(1, Ordering::SeqCst)); + drop(flow::base(&**self).ref_count().fetch_add(1, Ordering::SeqCst)); FlowRef { object: raw::TraitObject { vtable: self.object.vtable, diff --git a/components/layout/fragment.rs b/components/layout/fragment.rs index 8bad0a288b6..2eb26244059 100644 --- a/components/layout/fragment.rs +++ b/components/layout/fragment.rs @@ -164,7 +164,7 @@ impl SpecificFragmentInfo { SpecificFragmentInfo::InlineBlock(ref info) => &info.flow_ref, }; - flow::base(flow.deref()).restyle_damage + flow::base(&**flow).restyle_damage } pub fn get_type(&self) -> &'static str { @@ -1610,7 +1610,7 @@ impl Fragment { } SpecificFragmentInfo::InlineBlock(ref info) => { // See CSS 2.1 § 10.8.1. - let block_flow = info.flow_ref.deref().as_immutable_block(); + let block_flow = info.flow_ref.as_immutable_block(); let font_style = self.style.get_font_arc(); let font_metrics = text::font_metrics_for_style(layout_context.font_context(), font_style); diff --git a/components/layout/inline.rs b/components/layout/inline.rs index 67fc65b21e7..5944759f053 100644 --- a/components/layout/inline.rs +++ b/components/layout/inline.rs @@ -1194,14 +1194,14 @@ impl Flow for InlineFlow { &stacking_relative_border_box); match fragment.specific { SpecificFragmentInfo::InlineBlock(ref mut info) => { - flow::mut_base(info.flow_ref.deref_mut()).clip = clip; + flow::mut_base(&mut *info.flow_ref).clip = clip; let block_flow = info.flow_ref.as_block(); block_flow.base.absolute_position_info = self.base.absolute_position_info; block_flow.base.stacking_relative_position = stacking_relative_border_box.origin; } SpecificFragmentInfo::InlineAbsoluteHypothetical(ref mut info) => { - flow::mut_base(info.flow_ref.deref_mut()).clip = clip; + flow::mut_base(&mut *info.flow_ref).clip = clip; let block_flow = info.flow_ref.as_block(); block_flow.base.absolute_position_info = self.base.absolute_position_info; block_flow.base.stacking_relative_position = diff --git a/components/layout/layout_debug.rs b/components/layout/layout_debug.rs index aae0503d1eb..26d2f8b3ef7 100644 --- a/components/layout/layout_debug.rs +++ b/components/layout/layout_debug.rs @@ -64,7 +64,7 @@ impl Scope { STATE_KEY.with(|ref r| { match &mut *r.borrow_mut() { &Some(ref mut state) => { - let flow_trace = json::encode(&flow::base(state.flow_root.deref())); + let flow_trace = json::encode(&flow::base(&*state.flow_root)); let data = box ScopeData::new(name.clone(), flow_trace); state.scope_stack.push(data); } @@ -82,7 +82,7 @@ impl Drop for Scope { match &mut *r.borrow_mut() { &Some(ref mut state) => { let mut current_scope = state.scope_stack.pop().unwrap(); - current_scope.post = json::encode(&flow::base(state.flow_root.deref())); + current_scope.post = json::encode(&flow::base(&*state.flow_root)); let previous_scope = state.scope_stack.last_mut().unwrap(); previous_scope.children.push(current_scope); } @@ -105,7 +105,7 @@ pub fn begin_trace(flow_root: FlowRef) { assert!(STATE_KEY.with(|ref r| r.borrow().is_none())); STATE_KEY.with(|ref r| { - let flow_trace = json::encode(&flow::base(flow_root.deref())); + let flow_trace = json::encode(&flow::base(&*flow_root)); let state = State { scope_stack: vec![box ScopeData::new("root".to_owned(), flow_trace)], flow_root: flow_root.clone(), @@ -121,7 +121,7 @@ pub fn end_trace() { let mut task_state = STATE_KEY.with(|ref r| r.borrow_mut().take().unwrap()); assert!(task_state.scope_stack.len() == 1); let mut root_scope = task_state.scope_stack.pop().unwrap(); - root_scope.post = json::encode(&flow::base(task_state.flow_root.deref())); + root_scope.post = json::encode(&flow::base(&*task_state.flow_root)); let result = json::encode(&root_scope); let path = Path::new("layout_trace.json"); diff --git a/components/layout/layout_task.rs b/components/layout/layout_task.rs index b16efeaea16..56db9d816ee 100644 --- a/components/layout/layout_task.rs +++ b/components/layout/layout_task.rs @@ -222,8 +222,8 @@ enum RWGuard<'a> { impl<'a> Deref for RWGuard<'a> { fn deref(&self) -> &LayoutTaskData { match *self { - RWGuard::Held(ref x) => x.deref(), - RWGuard::Used(ref x) => x.deref(), + RWGuard::Held(ref x) => &**x, + RWGuard::Used(ref x) => &**x, } } } @@ -231,8 +231,8 @@ impl<'a> Deref for RWGuard<'a> { impl<'a> DerefMut for RWGuard<'a> { fn deref_mut(&mut self) -> &mut LayoutTaskData { match *self { - RWGuard::Held(ref mut x) => x.deref_mut(), - RWGuard::Used(ref mut x) => x.deref_mut(), + RWGuard::Held(ref mut x) => &mut **x, + RWGuard::Used(ref mut x) => &mut **x, } } } @@ -462,7 +462,7 @@ impl LayoutTask { { let mut rw_data = self.lock_rw_data(possibly_locked_rw_data); - match rw_data.deref_mut().parallel_traversal { + match (&mut *rw_data).parallel_traversal { None => {} Some(ref mut traversal) => traversal.shutdown(), } @@ -644,7 +644,7 @@ impl LayoutTask { flow::mut_base(&mut **layout_root).clip = ClippingRegion::from_rect(&data.page_clip_rect); - let rw_data = rw_data.deref_mut(); + let rw_data = &mut **rw_data; match rw_data.parallel_traversal { None => { sequential::build_display_list_for_subtree(layout_root, shared_layout_context); @@ -688,8 +688,8 @@ impl LayoutTask { root_flow.position.size.to_physical(root_flow.writing_mode) }; let mut display_list = box DisplayList::new(); - flow::mut_base(layout_root.deref_mut()).display_list_building_result - .add_to(&mut *display_list); + flow::mut_base(&mut **layout_root).display_list_building_result + .add_to(&mut *display_list); let paint_layer = Arc::new(PaintLayer::new(layout_root.layer_id(0), color, ScrollPolicy::Scrollable)); @@ -748,7 +748,7 @@ impl LayoutTask { rw_data.screen_size = current_screen_size; // Create a layout context for use throughout the following passes. - let mut shared_layout_context = self.build_shared_layout_context(rw_data.deref(), + let mut shared_layout_context = self.build_shared_layout_context(&*rw_data, node, &data.url); @@ -773,7 +773,7 @@ impl LayoutTask { if needs_reflow { self.try_get_layout_root(*node).map( - |mut flow| LayoutTask::reflow_all_nodes(flow.deref_mut())); + |mut flow| LayoutTask::reflow_all_nodes(&mut *flow)); } let mut layout_root = profile(TimeProfilerCategory::LayoutStyleRecalc, @@ -781,7 +781,7 @@ impl LayoutTask { self.time_profiler_chan.clone(), || { // Perform CSS selector matching and flow construction. - let rw_data = rw_data.deref_mut(); + let rw_data = &mut *rw_data; match rw_data.parallel_traversal { None => { sequential::traverse_dom_preorder(*node, &shared_layout_context); @@ -798,10 +798,9 @@ impl LayoutTask { self.profiler_metadata(data), self.time_profiler_chan.clone(), || { - if opts::get().nonincremental_layout || layout_root.deref_mut() - .compute_layout_damage() + if opts::get().nonincremental_layout || layout_root.compute_layout_damage() .contains(REFLOW_ENTIRE_DOCUMENT) { - layout_root.deref_mut().reflow_entire_document() + layout_root.reflow_entire_document() } }); @@ -820,7 +819,7 @@ impl LayoutTask { self.profiler_metadata(data), self.time_profiler_chan.clone(), || { - let rw_data = rw_data.deref_mut(); + let rw_data = &mut *rw_data; match rw_data.parallel_traversal { None => { // Sequential mode. diff --git a/components/layout/parallel.rs b/components/layout/parallel.rs index 5ec5c2c661b..6bd59cd8cc6 100644 --- a/components/layout/parallel.rs +++ b/components/layout/parallel.rs @@ -223,12 +223,12 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal { let flow: &mut FlowRef = mem::transmute(&unsafe_flow); // Perform the appropriate traversal. - if self.should_process(flow.deref_mut()) { - self.process(flow.deref_mut()); + if self.should_process(&mut **flow) { + self.process(&mut **flow); } - let base = flow::mut_base(flow.deref_mut()); + let base = flow::mut_base(&mut **flow); // Reset the count of children for the next layout traversal. base.parallel.children_count.store(base.children.len() as int, Ordering::Relaxed); @@ -244,7 +244,7 @@ trait ParallelPostorderFlowTraversal : PostorderFlowTraversal { // of our parent to finish processing? If so, we can continue // on with our parent; otherwise, we've gotta wait. let parent: &mut FlowRef = mem::transmute(&unsafe_parent); - let parent_base = flow::mut_base(parent.deref_mut()); + let parent_base = flow::mut_base(&mut **parent); if parent_base.parallel.children_count.fetch_sub(1, Ordering::SeqCst) == 1 { // We were the last child of our parent. Reflow our parent. unsafe_flow = unsafe_parent @@ -278,13 +278,13 @@ trait ParallelPreorderFlowTraversal : PreorderFlowTraversal { // Get a real flow. let flow: &mut FlowRef = mem::transmute(&unsafe_flow); - if self.should_process(flow.deref_mut()) { + if self.should_process(&mut **flow) { // Perform the appropriate traversal. - self.process(flow.deref_mut()); + self.process(&mut **flow); } // Possibly enqueue the children. - for kid in flow::child_iter(flow.deref_mut()) { + for kid in flow::child_iter(&mut **flow) { had_children = true; proxy.push(WorkUnit { fun: top_down_func, @@ -427,7 +427,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef, if opts::get().bubble_inline_sizes_separately { let layout_context = LayoutContext::new(shared_layout_context); let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context }; - root.deref_mut().traverse_postorder(&bubble_inline_sizes); + root.traverse_postorder(&bubble_inline_sizes); } queue.data = shared_layout_context as *const _; diff --git a/components/layout/sequential.rs b/components/layout/sequential.rs index 1be77041113..b91aad6a11c 100644 --- a/components/layout/sequential.rs +++ b/components/layout/sequential.rs @@ -59,7 +59,7 @@ pub fn traverse_flow_tree_preorder(root: &mut FlowRef, let layout_context = LayoutContext::new(shared_layout_context); - let root = root.deref_mut(); + let root = &mut **root; if opts::get().bubble_inline_sizes_separately { let bubble_inline_sizes = BubbleISizes { layout_context: &layout_context }; @@ -94,7 +94,7 @@ pub fn build_display_list_for_subtree(root: &mut FlowRef, let compute_absolute_positions = ComputeAbsolutePositions { layout_context: &layout_context }; let build_display_list = BuildDisplayList { layout_context: &layout_context }; - doit(root.deref_mut(), compute_absolute_positions, build_display_list); + doit(&mut **root, compute_absolute_positions, build_display_list); } pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut FlowRef, @@ -117,5 +117,5 @@ pub fn iterate_through_flow_tree_fragment_border_boxes(root: &mut FlowRef, } } - doit(root.deref_mut(), iterator, &ZERO_POINT); + doit(&mut **root, iterator, &ZERO_POINT); } diff --git a/components/script/dom/bindings/js.rs b/components/script/dom/bindings/js.rs index 40230e9198e..c56618d2a13 100644 --- a/components/script/dom/bindings/js.rs +++ b/components/script/dom/bindings/js.rs @@ -634,7 +634,7 @@ impl<'a, T: Reflectable> JSRef<'a, T> { impl<'a, T: Reflectable> Reflectable for JSRef<'a, T> { fn reflector<'a>(&'a self) -> &'a Reflector { - self.deref().reflector() + (**self).reflector() } } diff --git a/components/script/dom/element.rs b/components/script/dom/element.rs index efafdbe7b11..98dcb3b0be1 100644 --- a/components/script/dom/element.rs +++ b/components/script/dom/element.rs @@ -505,7 +505,7 @@ impl<'a> ElementHelpers<'a> for JSRef<'a, Element> { fn update_inline_style(self, property_decl: style::PropertyDeclaration, style_priority: StylePriority) { let mut inline_declarations = self.style_attribute().borrow_mut(); - if let Some(ref mut declarations) = *inline_declarations.deref_mut() { + if let &Some(ref mut declarations) = &mut *inline_declarations { let existing_declarations = if style_priority == StylePriority::Important { declarations.important.make_unique() } else { diff --git a/components/script/dom/node.rs b/components/script/dom/node.rs index d23c14a586f..2d86c48c2d6 100644 --- a/components/script/dom/node.rs +++ b/components/script/dom/node.rs @@ -515,7 +515,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } fn is_in_doc(self) -> bool { - self.deref().flags.get().contains(IS_IN_DOC) + self.flags.get().contains(IS_IN_DOC) } /// Returns the type ID of this node. Fails if this node is borrowed mutably. @@ -728,7 +728,7 @@ impl<'a> NodeHelpers<'a> for JSRef<'a, Node> { } fn to_trusted_node_address(self) -> TrustedNodeAddress { - TrustedNodeAddress(self.deref() as *const Node as *const libc::c_void) + TrustedNodeAddress(&*self as *const Node as *const libc::c_void) } fn get_bounding_content_box(self) -> Rect { @@ -1019,7 +1019,7 @@ pub struct NodeChildrenIterator<'a> { impl<'a> Iterator> for NodeChildrenIterator<'a> { fn next(&mut self) -> Option> { let node = self.current; - self.current = node.and_then(|node| node.next_sibling().map(|node| *node.root().deref())); + self.current = node.and_then(|node| node.next_sibling().map(|node| *node.root())); node } } @@ -1043,7 +1043,7 @@ pub struct AncestorIterator<'a> { impl<'a> Iterator> for AncestorIterator<'a> { fn next(&mut self) -> Option> { let node = self.current; - self.current = node.and_then(|node| node.parent_node().map(|node| *node.root().deref())); + self.current = node.and_then(|node| node.parent_node().map(|node| *node.root())); node } } diff --git a/components/util/lib.rs b/components/util/lib.rs index 524990368d5..9a97bdbbf78 100644 --- a/components/util/lib.rs +++ b/components/util/lib.rs @@ -69,7 +69,7 @@ pub fn breakpoint() { // Workaround for lack of `ptr_eq` on Arcs... #[inline] pub fn arc_ptr_eq(a: &Arc, b: &Arc) -> bool { - let a: &T = a.deref(); - let b: &T = b.deref(); + let a: &T = &**a; + let b: &T = &**b; (a as *const T) == (b as *const T) }