aboutsummaryrefslogtreecommitdiffstats
path: root/components/util/vec.rs
diff options
context:
space:
mode:
authorbors-servo <metajack+bors@gmail.com>2015-05-05 09:11:30 -0500
committerbors-servo <metajack+bors@gmail.com>2015-05-05 09:11:30 -0500
commit49aed6555dbc008c1a378c5cbb303f5467232b6b (patch)
tree9146cdd7126ead59c57cacbaa04eda0f16761f65 /components/util/vec.rs
parent7b87085c1880c60aa3be5b3ec4572a0d93fd5537 (diff)
parentef8edd4e87aeb3cc71dfd9da2f69437080f5410e (diff)
downloadservo-49aed6555dbc008c1a378c5cbb303f5467232b6b.tar.gz
servo-49aed6555dbc008c1a378c5cbb303f5467232b6b.zip
Auto merge of #5935 - servo:rustup_2015-04-25, r=Ms2ger
r? everybody <!-- Reviewable:start --> [<img src="https://reviewable.io/review_button.png" height=40 alt="Review on Reviewable"/>](https://reviewable.io/reviews/servo/servo/5935) <!-- Reviewable:end -->
Diffstat (limited to 'components/util/vec.rs')
-rw-r--r--components/util/vec.rs60
1 files changed, 47 insertions, 13 deletions
diff --git a/components/util/vec.rs b/components/util/vec.rs
index 238118aac1d..c660d26584a 100644
--- a/components/util/vec.rs
+++ b/components/util/vec.rs
@@ -2,10 +2,11 @@
* 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 selectors::smallvec::VecLike;
+use super::smallvec::VecLike;
use std::cmp::{PartialOrd, PartialEq, Ordering};
-use std::iter::range_step;
+use std::marker::PhantomData;
+use std::ops;
/// FIXME(pcwalton): Workaround for lack of unboxed closures. This is called in
/// performance-critical code, so a closure is insufficient.
@@ -68,7 +69,7 @@ impl<T:PartialEq + PartialOrd + Ord> Comparator<T,T> for DefaultComparator {
// TODO(pcwalton): Speed up with SIMD, or better yet, find some way to not do this.
pub fn byte_swap(data: &mut [u8]) {
let length = data.len();
- for i in range_step(0, length, 4) {
+ for i in (0..length).step_by(4) {
let r = data[i + 2];
data[i + 2] = data[i + 0];
data[i + 0] = r;
@@ -76,14 +77,16 @@ pub fn byte_swap(data: &mut [u8]) {
}
/// A `VecLike` that only tracks whether or not something was ever pushed to it.
-pub struct ForgetfulSink {
+pub struct ForgetfulSink<T> {
empty: bool,
+ _data: PhantomData<T>,
}
-impl ForgetfulSink {
- pub fn new() -> ForgetfulSink {
+impl<T> ForgetfulSink<T> {
+ pub fn new() -> ForgetfulSink<T> {
ForgetfulSink {
empty: true,
+ _data: PhantomData,
}
}
@@ -92,19 +95,50 @@ impl ForgetfulSink {
}
}
-impl<T> VecLike<T> for ForgetfulSink {
- #[inline]
- fn vec_len(&self) -> usize {
+impl<T> ops::Deref for ForgetfulSink<T> {
+ type Target = [T];
+ fn deref(&self) -> &[T] {
unreachable!()
}
+}
- #[inline]
- fn vec_push(&mut self, _value: T) {
- self.empty = false;
+impl<T> ops::DerefMut for ForgetfulSink<T> {
+ fn deref_mut(&mut self) -> &mut [T] {
+ unreachable!()
}
+}
+macro_rules! impl_index {
+ ($index_type: ty, $output_type: ty) => {
+ impl<T> ops::Index<$index_type> for ForgetfulSink<T> {
+ type Output = $output_type;
+ fn index(&self, _index: $index_type) -> &$output_type {
+ unreachable!()
+ }
+ }
+
+ impl<T> ops::IndexMut<$index_type> for ForgetfulSink<T> {
+ fn index_mut(&mut self, _index: $index_type) -> &mut $output_type {
+ unreachable!()
+ }
+ }
+ }
+}
+
+impl_index!(usize, T);
+impl_index!(ops::Range<usize>, [T]);
+impl_index!(ops::RangeFrom<usize>, [T]);
+impl_index!(ops::RangeTo<usize>, [T]);
+impl_index!(ops::RangeFull, [T]);
+
+impl<T> VecLike<T> for ForgetfulSink<T> {
#[inline]
- fn vec_slice_mut<'a>(&'a mut self, _start: usize, _end: usize) -> &'a mut [T] {
+ fn len(&self) -> usize {
unreachable!()
}
+
+ #[inline]
+ fn push(&mut self, _value: T) {
+ self.empty = false;
+ }
}