aboutsummaryrefslogtreecommitdiffstats
path: root/components/layout/linked_list.rs
diff options
context:
space:
mode:
authorAnthony Ramine <n.oxyde@gmail.com>2016-06-29 17:23:04 +0200
committerAnthony Ramine <n.oxyde@gmail.com>2016-06-29 17:23:04 +0200
commit304108417665a7c4a43cedde7bb9979adeab4883 (patch)
treef440cd058f36523d1f2dddb062fefcfd3860b476 /components/layout/linked_list.rs
parent7b2080c5b7c933f74c0d92249a66f8602340ebbe (diff)
downloadservo-304108417665a7c4a43cedde7bb9979adeab4883.tar.gz
servo-304108417665a7c4a43cedde7bb9979adeab4883.zip
Move util::linked_list to layout
Diffstat (limited to 'components/layout/linked_list.rs')
-rw-r--r--components/layout/linked_list.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/components/layout/linked_list.rs b/components/layout/linked_list.rs
new file mode 100644
index 00000000000..5114f02c0e4
--- /dev/null
+++ b/components/layout/linked_list.rs
@@ -0,0 +1,21 @@
+/* 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/. */
+
+//! Utility functions for doubly-linked lists.
+
+use std::collections::LinkedList;
+use std::mem;
+
+/// Splits the head off a list in O(1) time, and returns the head.
+pub fn split_off_head<T>(list: &mut LinkedList<T>) -> LinkedList<T> {
+ 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 LinkedList<T>, other: &mut LinkedList<T>) {
+ other.append(this);
+ mem::swap(this, other);
+}