mirror of
https://github.com/servo/servo.git
synced 2025-08-03 12:40:06 +01:00
Move util::vec::ForgetfulSink to style::sink and simplify it
This commit is contained in:
parent
51ff916e09
commit
a5b524d559
14 changed files with 58 additions and 89 deletions
|
@ -31,7 +31,6 @@ rand = "0.3"
|
|||
rustc-serialize = "0.3"
|
||||
serde = {version = "0.7.11", optional = true}
|
||||
serde_macros = {version = "0.7.11", optional = true}
|
||||
smallvec = "0.1"
|
||||
url = "1.0.0"
|
||||
|
||||
[target.'cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))'.dependencies]
|
||||
|
|
|
@ -27,7 +27,6 @@ extern crate num_traits;
|
|||
extern crate rand;
|
||||
extern crate rustc_serialize;
|
||||
#[cfg(feature = "servo")] extern crate serde;
|
||||
extern crate smallvec;
|
||||
extern crate url;
|
||||
#[cfg(all(unix, not(target_os = "macos"), not(target_os = "ios"), not(target_os = "android")))]
|
||||
extern crate xdg;
|
||||
|
|
|
@ -2,10 +2,6 @@
|
|||
* 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::marker::PhantomData;
|
||||
use std::ops;
|
||||
use super::smallvec::VecLike;
|
||||
|
||||
// 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();
|
||||
|
@ -18,70 +14,3 @@ pub fn byte_swap(data: &mut [u8]) {
|
|||
i += 4;
|
||||
}
|
||||
}
|
||||
|
||||
/// A `VecLike` that only tracks whether or not something was ever pushed to it.
|
||||
pub struct ForgetfulSink<T> {
|
||||
empty: bool,
|
||||
_data: PhantomData<T>,
|
||||
}
|
||||
|
||||
impl<T> ForgetfulSink<T> {
|
||||
pub fn new() -> ForgetfulSink<T> {
|
||||
ForgetfulSink {
|
||||
empty: true,
|
||||
_data: PhantomData,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.empty
|
||||
}
|
||||
}
|
||||
|
||||
impl<T> ops::Deref for ForgetfulSink<T> {
|
||||
type Target = [T];
|
||||
fn deref(&self) -> &[T] {
|
||||
unreachable!()
|
||||
}
|
||||
}
|
||||
|
||||
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 len(&self) -> usize {
|
||||
unreachable!()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn push(&mut self, _value: T) {
|
||||
self.empty = false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue