зеркало из https://github.com/mozilla/gecko-dev.git
servo: Merge #4904 - Replace util::dlist code with new collections::DList methods (from mbrubeck:dlist); r=pcwalton
r? @pcwalton Source-Repo: https://github.com/servo/servo Source-Revision: 26aee53c827c4db517171cd89786d894b1ceb76c
This commit is contained in:
Родитель
13868c9015
Коммит
c7d0095a59
|
@ -109,14 +109,12 @@ impl DisplayList {
|
|||
/// `other` in the process.
|
||||
#[inline]
|
||||
pub fn append_from(&mut self, other: &mut DisplayList) {
|
||||
servo_dlist::append_from(&mut self.background_and_borders,
|
||||
&mut other.background_and_borders);
|
||||
servo_dlist::append_from(&mut self.block_backgrounds_and_borders,
|
||||
&mut other.block_backgrounds_and_borders);
|
||||
servo_dlist::append_from(&mut self.floats, &mut other.floats);
|
||||
servo_dlist::append_from(&mut self.content, &mut other.content);
|
||||
servo_dlist::append_from(&mut self.outlines, &mut other.outlines);
|
||||
servo_dlist::append_from(&mut self.children, &mut other.children);
|
||||
self.background_and_borders.append(&mut other.background_and_borders);
|
||||
self.block_backgrounds_and_borders.append(&mut other.block_backgrounds_and_borders);
|
||||
self.floats.append(&mut other.floats);
|
||||
self.content.append(&mut other.content);
|
||||
self.outlines.append(&mut other.outlines);
|
||||
self.children.append(&mut other.children);
|
||||
}
|
||||
|
||||
/// Merges all display items from all non-float stacking levels to the `float` stacking level.
|
||||
|
|
|
@ -50,13 +50,13 @@ impl TextRunScanner {
|
|||
let mut last_whitespace = true;
|
||||
while !fragments.is_empty() {
|
||||
// Create a clump.
|
||||
self.clump.append(&mut dlist::split(&mut fragments));
|
||||
self.clump.append(&mut dlist::split_off_head(&mut fragments));
|
||||
while !fragments.is_empty() && self.clump
|
||||
.back()
|
||||
.unwrap()
|
||||
.can_merge_with_fragment(fragments.front()
|
||||
.unwrap()) {
|
||||
self.clump.append(&mut dlist::split(&mut fragments));
|
||||
self.clump.append(&mut dlist::split_off_head(&mut fragments));
|
||||
}
|
||||
|
||||
// Flush that clump to the list of fragments we're building up.
|
||||
|
|
|
@ -6,120 +6,20 @@
|
|||
|
||||
use std::collections::DList;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
|
||||
struct RawDList<T> {
|
||||
length: uint,
|
||||
head: *mut RawNode<T>,
|
||||
tail: *mut RawNode<T>,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
struct RawNode<T> {
|
||||
next: *mut RawNode<T>,
|
||||
prev: *mut RawNode<T>,
|
||||
value: T,
|
||||
}
|
||||
|
||||
#[unsafe_destructor]
|
||||
impl<T> Drop for RawDList<T> {
|
||||
fn drop(&mut self) {
|
||||
panic!("shouldn't happen")
|
||||
}
|
||||
}
|
||||
|
||||
/// Workaround for a missing method on Rust's `DList` type. Splits the head off a list in O(1)
|
||||
/// time.
|
||||
pub fn split<T>(list: &mut DList<T>) -> DList<T> {
|
||||
let list = unsafe {
|
||||
mem::transmute::<&mut DList<T>,&mut RawDList<T>>(list)
|
||||
};
|
||||
|
||||
if list.length == 0 {
|
||||
panic!("split_dlist(): empty list")
|
||||
}
|
||||
let head_node = mem::replace(&mut list.head, ptr::null_mut());
|
||||
let head_list = RawDList {
|
||||
length: 1,
|
||||
head: head_node,
|
||||
tail: head_node,
|
||||
};
|
||||
debug_assert!(list.head.is_null());
|
||||
|
||||
unsafe {
|
||||
mem::swap(&mut (*head_list.head).next, &mut list.head);
|
||||
debug_assert!((*head_list.head).next.is_null());
|
||||
debug_assert!((*head_list.head).prev.is_null());
|
||||
(*head_list.head).prev = ptr::null_mut();
|
||||
}
|
||||
|
||||
list.length -= 1;
|
||||
if list.length == 0 {
|
||||
list.tail = ptr::null_mut()
|
||||
} else {
|
||||
if list.length == 1 {
|
||||
list.tail = list.head
|
||||
}
|
||||
|
||||
unsafe {
|
||||
(*list.head).prev = ptr::null_mut()
|
||||
}
|
||||
}
|
||||
|
||||
unsafe {
|
||||
mem::transmute::<RawDList<T>,DList<T>>(head_list)
|
||||
}
|
||||
}
|
||||
|
||||
/// Appends the items in the other list to this one, leaving the other list empty.
|
||||
#[inline]
|
||||
pub fn append_from<T>(this: &mut DList<T>, other: &mut DList<T>) {
|
||||
unsafe {
|
||||
let this = mem::transmute::<&mut DList<T>,&mut RawDList<T>>(this);
|
||||
let other = mem::transmute::<&mut DList<T>,&mut RawDList<T>>(other);
|
||||
if this.length == 0 {
|
||||
this.head = mem::replace(&mut other.head, ptr::null_mut());
|
||||
this.tail = mem::replace(&mut other.tail, ptr::null_mut());
|
||||
this.length = mem::replace(&mut other.length, 0);
|
||||
return
|
||||
}
|
||||
|
||||
let old_other_head = mem::replace(&mut other.head, ptr::null_mut());
|
||||
if old_other_head.is_null() {
|
||||
return
|
||||
}
|
||||
(*old_other_head).prev = this.tail;
|
||||
(*this.tail).next = old_other_head;
|
||||
|
||||
this.tail = mem::replace(&mut other.tail, ptr::null_mut());
|
||||
this.length += other.length;
|
||||
other.length = 0;
|
||||
/// Splits the head off a list in O(1) time, and returns the head.
|
||||
pub fn split_off_head<T>(list: &mut DList<T>) -> DList<T> {
|
||||
// FIXME: Work around https://github.com/rust-lang/rust/issues/22244
|
||||
if list.len() == 1 {
|
||||
return mem::replace(list, DList::new());
|
||||
}
|
||||
let tail = list.split_off(1);
|
||||
mem::replace(list, tail)
|
||||
}
|
||||
|
||||
/// Prepends the items in the other list to this one, leaving the other list empty.
|
||||
#[inline]
|
||||
pub fn prepend_from<T>(this: &mut DList<T>, other: &mut DList<T>) {
|
||||
unsafe {
|
||||
let this = mem::transmute::<&mut DList<T>,&mut RawDList<T>>(this);
|
||||
let other = mem::transmute::<&mut DList<T>,&mut RawDList<T>>(other);
|
||||
if this.length == 0 {
|
||||
this.head = mem::replace(&mut other.head, ptr::null_mut());
|
||||
this.tail = mem::replace(&mut other.tail, ptr::null_mut());
|
||||
this.length = mem::replace(&mut other.length, 0);
|
||||
return
|
||||
}
|
||||
|
||||
let old_other_tail = mem::replace(&mut other.tail, ptr::null_mut());
|
||||
if old_other_tail.is_null() {
|
||||
return
|
||||
}
|
||||
(*old_other_tail).next = this.head;
|
||||
(*this.head).prev = old_other_tail;
|
||||
|
||||
this.head = mem::replace(&mut other.head, ptr::null_mut());
|
||||
this.length += other.length;
|
||||
other.length = 0;
|
||||
}
|
||||
other.append(this);
|
||||
mem::swap(this, other);
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче