diff options
author | bors-servo <metajack+bors@gmail.com> | 2014-10-28 13:48:58 -0600 |
---|---|---|
committer | bors-servo <metajack+bors@gmail.com> | 2014-10-28 13:48:58 -0600 |
commit | c109f6ff772c75cc79b10cfdf8ebccdec9b8465e (patch) | |
tree | 9ed35142ee148b78d51055dd8b4312b4a02fa477 | |
parent | 2d8bd10abefe5cee9b60900911d41bb47323d248 (diff) | |
parent | 1a28960bd257c871a530a63848b56040cb8cbf18 (diff) | |
download | servo-c109f6ff772c75cc79b10cfdf8ebccdec9b8465e.tar.gz servo-c109f6ff772c75cc79b10cfdf8ebccdec9b8465e.zip |
auto merge of #3831 : pcwalton/servo/append-from, r=mbrubeck
This is tracked upstream as Rust bug #18402.
r? @mbrubeck
-rw-r--r-- | components/util/dlist.rs | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/components/util/dlist.rs b/components/util/dlist.rs index 14a1b5d4cdf..420a77a2698 100644 --- a/components/util/dlist.rs +++ b/components/util/dlist.rs @@ -66,3 +66,29 @@ pub fn split<T>(list: &mut DList<T>) -> DList<T> { } } +/// 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, None); + this.tail = mem::replace(&mut other.tail, ptr::null_mut()); + this.length = mem::replace(&mut other.length, 0); + return + } + + (*this.tail).next = match mem::replace(&mut other.head, None) { + None => return, + Some(mut head) => { + head.prev = this.tail; + Some(head) + } + }; + this.tail = mem::replace(&mut other.tail, ptr::null_mut()); + this.length += other.length; + other.length = 0; + } +} + |