diff options
Diffstat (limited to 'src/libcore/slice.rs')
| -rw-r--r-- | src/libcore/slice.rs | 285 |
1 files changed, 8 insertions, 277 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 5847a6177d7..6b24592b17f 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -176,29 +176,16 @@ pub trait ImmutableSlice<'a, T> { #[unstable = "name may change"] fn tail(&self) -> &'a [T]; - /// Returns all but the first `n' elements of a slice. - #[deprecated = "use slice_from"] - fn tailn(&self, n: uint) -> &'a [T]; - /// Returns all but the last element of a slice. #[unstable = "name may change"] fn init(&self) -> &'a [T]; - /// Returns all but the last `n' elements of a slice. - #[deprecated = "use slice_to but note the arguments are different"] - fn initn(&self, n: uint) -> &'a [T]; - /// Returns the last element of a slice, or `None` if it is empty. #[unstable = "name may change"] fn last(&self) -> Option<&'a T>; /// Returns a pointer to the element at the given index, without doing /// bounds checking. - #[deprecated = "renamed to `unsafe_get`"] - unsafe fn unsafe_ref(self, index: uint) -> &'a T; - - /// Returns a pointer to the element at the given index, without doing - /// bounds checking. #[unstable] unsafe fn unsafe_get(self, index: uint) -> &'a T; @@ -212,10 +199,6 @@ pub trait ImmutableSlice<'a, T> { #[unstable] fn as_ptr(&self) -> *const T; - /// Deprecated: use `binary_search`. - #[deprecated = "use binary_search"] - fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint>; - /// Binary search a sorted slice with a comparator function. /// /// The comparator function should implement an order consistent @@ -251,44 +234,6 @@ pub trait ImmutableSlice<'a, T> { /// ``` #[unstable = "waiting on unboxed closures"] fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult; - - /** - * Returns an immutable reference to the first element in this slice - * and adjusts the slice in place so that it no longer contains - * that element. O(1). - * - * Equivalent to: - * - * ```ignore - * if self.len() == 0 { return None } - * let head = &self[0]; - * *self = self[1..]; - * Some(head) - * ``` - * - * Returns `None` if vector is empty - */ - #[deprecated = "find some other way. sorry"] - fn shift_ref(&mut self) -> Option<&'a T>; - - /** - * Returns an immutable reference to the last element in this slice - * and adjusts the slice in place so that it no longer contains - * that element. O(1). - * - * Equivalent to: - * - * ```ignore - * if self.len() == 0 { return None; } - * let tail = &self[self.len() - 1]; - * *self = self[..self.len() - 1]; - * Some(tail) - * ``` - * - * Returns `None` if slice is empty. - */ - #[deprecated = "find some other way. sorry"] - fn pop_ref(&mut self) -> Option<&'a T>; } #[unstable] @@ -389,32 +334,16 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { fn tail(&self) -> &'a [T] { (*self)[1..] } #[inline] - #[deprecated = "use slice_from"] - fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] } - - #[inline] fn init(&self) -> &'a [T] { (*self)[..self.len() - 1] } #[inline] - #[deprecated = "use slice_to but note the arguments are different"] - fn initn(&self, n: uint) -> &'a [T] { - (*self)[..self.len() - n] - } - - #[inline] fn last(&self) -> Option<&'a T> { if self.len() == 0 { None } else { Some(&self[self.len() - 1]) } } #[inline] - #[deprecated = "renamed to `unsafe_get`"] - unsafe fn unsafe_ref(self, index: uint) -> &'a T { - transmute(self.repr().data.offset(index as int)) - } - - #[inline] unsafe fn unsafe_get(self, index: uint) -> &'a T { transmute(self.repr().data.offset(index as int)) } @@ -424,27 +353,6 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { self.repr().data } - - #[deprecated = "use binary_search"] - fn bsearch(&self, f: |&T| -> Ordering) -> Option<uint> { - let mut base : uint = 0; - let mut lim : uint = self.len(); - - while lim != 0 { - let ix = base + (lim >> 1); - match f(&self[ix]) { - Equal => return Some(ix), - Less => { - base = ix + 1; - lim -= 1; - } - Greater => () - } - lim >>= 1; - } - return None; - } - #[unstable] fn binary_search(&self, f: |&T| -> Ordering) -> BinarySearchResult { let mut base : uint = 0; @@ -464,26 +372,6 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { } return NotFound(base); } - - fn shift_ref(&mut self) -> Option<&'a T> { - unsafe { - let s: &mut RawSlice<T> = transmute(self); - match raw::shift_ptr(s) { - Some(p) => Some(&*p), - None => None - } - } - } - - fn pop_ref(&mut self) -> Option<&'a T> { - unsafe { - let s: &mut RawSlice<T> = transmute(self); - match raw::pop_ptr(s) { - Some(p) => Some(&*p), - None => None - } - } - } } @@ -557,12 +445,6 @@ pub trait MutableSlice<'a, T> { /// Primarily intended for getting a &mut [T] from a [T, ..N]. fn as_mut_slice(self) -> &'a mut [T]; - /// Deprecated: use `slice_mut`. - #[deprecated = "use slice_mut"] - fn mut_slice(self, start: uint, end: uint) -> &'a mut [T] { - self.slice_mut(start, end) - } - /// Returns a mutable subslice spanning the interval [`start`, `end`). /// /// Fails when the end of the new slice lies beyond the end of the @@ -572,12 +454,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on final error conventions"] fn slice_mut(self, start: uint, end: uint) -> &'a mut [T]; - /// Deprecated: use `slice_from_mut`. - #[deprecated = "use slice_from_mut"] - fn mut_slice_from(self, start: uint) -> &'a mut [T] { - self.slice_from_mut(start) - } - /// Returns a mutable subslice from `start` to the end of the slice. /// /// Fails when `start` is strictly greater than the length of the original slice. @@ -586,12 +462,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on final error conventions"] fn slice_from_mut(self, start: uint) -> &'a mut [T]; - /// Deprecated: use `slice_to_mut`. - #[deprecated = "use slice_to_mut"] - fn mut_slice_to(self, end: uint) -> &'a mut [T] { - self.slice_to_mut(end) - } - /// Returns a mutable subslice from the start of the slice to `end`. /// /// Fails when `end` is strictly greater than the length of the original slice. @@ -600,12 +470,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on final error conventions"] fn slice_to_mut(self, end: uint) -> &'a mut [T]; - /// Deprecated: use `iter_mut`. - #[deprecated = "use iter_mut"] - fn mut_iter(self) -> MutItems<'a, T> { - self.iter_mut() - } - /// Returns an iterator that allows modifying each value #[unstable = "waiting on iterator type name conventions"] fn iter_mut(self) -> MutItems<'a, T>; @@ -622,22 +486,10 @@ pub trait MutableSlice<'a, T> { #[unstable = "name may change"] fn init_mut(self) -> &'a mut [T]; - /// Deprecated: use `last_mut`. - #[deprecated = "use last_mut"] - fn mut_last(self) -> Option<&'a mut T> { - self.last_mut() - } - /// Returns a mutable pointer to the last item in the slice. #[unstable = "name may change"] fn last_mut(self) -> Option<&'a mut T>; - /// Deprecated: use `split_mut`. - #[deprecated = "use split_mut"] - fn mut_split(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T> { - self.split_mut(pred) - } - /// Returns an iterator over mutable subslices separated by elements that /// match `pred`. The matched element is not contained in the subslices. #[unstable = "waiting on unboxed closures, iterator type name conventions"] @@ -656,12 +508,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on unboxed closures, iterator type name conventions"] fn rsplitn_mut(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<MutSplits<'a, T>>; - /// Deprecated: use `chunks_mut`. - #[deprecated = "use chunks_mut"] - fn mut_chunks(self, chunk_size: uint) -> MutChunks<'a, T> { - self.chunks_mut(chunk_size) - } - /// Returns an iterator over `chunk_size` elements of the slice at a time. /// The chunks are mutable and do not overlap. If `chunk_size` does /// not divide the length of the slice, then the last chunk will not @@ -673,44 +519,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on iterator type name conventions"] fn chunks_mut(self, chunk_size: uint) -> MutChunks<'a, T>; - /** - * Returns a mutable reference to the first element in this slice - * and adjusts the slice in place so that it no longer contains - * that element. O(1). - * - * Equivalent to: - * - * ```ignore - * if self.len() == 0 { return None; } - * let head = &mut self[0]; - * *self = self[mut 1..]; - * Some(head) - * ``` - * - * Returns `None` if slice is empty - */ - #[deprecated = "use iter_mut"] - fn mut_shift_ref(&mut self) -> Option<&'a mut T>; - - /** - * Returns a mutable reference to the last element in this slice - * and adjusts the slice in place so that it no longer contains - * that element. O(1). - * - * Equivalent to: - * - * ```ignore - * if self.len() == 0 { return None; } - * let tail = &mut self[self.len() - 1]; - * *self = self[mut ..self.len() - 1]; - * Some(tail) - * ``` - * - * Returns `None` if slice is empty. - */ - #[deprecated = "use iter_mut"] - fn mut_pop_ref(&mut self) -> Option<&'a mut T>; - /// Swaps two elements in a slice. /// /// Fails if `a` or `b` are out of bounds. @@ -730,12 +538,6 @@ pub trait MutableSlice<'a, T> { #[unstable = "waiting on final error conventions"] fn swap(self, a: uint, b: uint); - /// Deprecated: use `split_at_mut`. - #[deprecated = "use split_at_mut"] - fn mut_split_at(self, mid: uint) -> (&'a mut [T], &'a mut [T]) { - self.split_at_mut(mid) - } - /// Divides one `&mut` into two at an index. /// /// The first will contain all indices from `[0, mid)` (excluding @@ -783,12 +585,6 @@ pub trait MutableSlice<'a, T> { #[experimental = "may be moved to iterators instead"] fn reverse(self); - /// Deprecated: use `unsafe_mut`. - #[deprecated = "use unsafe_mut"] - unsafe fn unsafe_mut_ref(self, index: uint) -> &'a mut T { - self.unsafe_mut(index) - } - /// Returns an unsafe mutable pointer to the element in index #[experimental = "waiting on unsafe conventions"] unsafe fn unsafe_mut(self, index: uint) -> &'a mut T; @@ -803,18 +599,6 @@ pub trait MutableSlice<'a, T> { #[inline] #[unstable] fn as_mut_ptr(self) -> *mut T; - - /// Deprecated: use `*foo.as_mut_ptr().offset(index) = val` instead. - #[deprecated = "use `*foo.as_mut_ptr().offset(index) = val`"] - unsafe fn unsafe_set(self, index: uint, val: T); - - /// Deprecated: use `ptr::write(foo.as_mut_ptr().offset(i), val)` instead. - #[deprecated = "use `ptr::write(foo.as_mut_ptr().offset(i), val)`"] - unsafe fn init_elem(self, i: uint, val: T); - - /// Deprecated: use `as_mut_ptr` and `ptr::copy_memory` instead. - #[deprecated = "use as_mut_ptr and ptr::copy_memory"] - unsafe fn copy_memory(self, src: &[T]); } #[experimental = "trait is experimental"] @@ -920,30 +704,6 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { MutChunks { v: self, chunk_size: chunk_size } } - fn mut_shift_ref(&mut self) -> Option<&'a mut T> { - unsafe { - let s: &mut RawSlice<T> = transmute(self); - match raw::shift_ptr(s) { - // FIXME #13933: this `&` -> `&mut` cast is a little - // dubious - Some(p) => Some(&mut *(p as *mut _)), - None => None, - } - } - } - - fn mut_pop_ref(&mut self) -> Option<&'a mut T> { - unsafe { - let s: &mut RawSlice<T> = transmute(self); - match raw::pop_ptr(s) { - // FIXME #13933: this `&` -> `&mut` cast is a little - // dubious - Some(p) => Some(&mut *(p as *mut _)), - None => None, - } - } - } - fn swap(self, a: uint, b: uint) { unsafe { // Can't take two mutable loans from one vector, so instead just cast @@ -977,23 +737,6 @@ impl<'a,T> MutableSlice<'a, T> for &'a mut [T] { fn as_mut_ptr(self) -> *mut T { self.repr().data as *mut T } - - #[inline] - unsafe fn unsafe_set(self, index: uint, val: T) { - *self.unsafe_mut(index) = val; - } - - #[inline] - unsafe fn init_elem(self, i: uint, val: T) { - ptr::write(&mut (*self.as_mut_ptr().offset(i as int)), val); - } - - #[inline] - unsafe fn copy_memory(self, src: &[T]) { - let len_src = src.len(); - assert!(self.len() >= len_src); - ptr::copy_nonoverlapping_memory(self.as_mut_ptr(), src.as_ptr(), len_src) - } } /// Extension methods for slices containing `PartialEq` elements. @@ -1048,10 +791,6 @@ impl<'a,T:PartialEq> ImmutablePartialEqSlice<T> for &'a [T] { /// Extension methods for slices containing `Ord` elements. #[unstable = "may merge with other traits"] pub trait ImmutableOrdSlice<T: Ord> { - /// Deprecated: use `binary_search_elem`. - #[deprecated = "use binary_search_elem"] - fn bsearch_elem(&self, x: &T) -> Option<uint>; - /// Binary search a sorted slice for a given element. /// /// If the value is found then `Found` is returned, containing the @@ -1082,12 +821,6 @@ pub trait ImmutableOrdSlice<T: Ord> { #[unstable = "trait is unstable"] impl<'a, T: Ord> ImmutableOrdSlice<T> for &'a [T] { - #[deprecated = "use binary_search_elem"] - #[allow(deprecated)] - fn bsearch_elem(&self, x: &T) -> Option<uint> { - self.bsearch(|p| p.cmp(x)) - } - #[unstable] fn binary_search_elem(&self, x: &T) -> BinarySearchResult { self.binary_search(|p| p.cmp(x)) @@ -1100,12 +833,6 @@ pub trait MutableCloneableSlice<T> { /// Copies as many elements from `src` as it can into `self` (the /// shorter of `self.len()` and `src.len()`). Returns the number /// of elements copied. - #[deprecated = "renamed to clone_from_slice"] - fn copy_from(self, s: &[T]) -> uint { self.clone_from_slice(s) } - - /// Copies as many elements from `src` as it can into `self` (the - /// shorter of `self.len()` and `src.len()`). Returns the number - /// of elements copied. /// /// # Example /// @@ -1780,7 +1507,7 @@ pub mod raw { pub mod bytes { use collections::Collection; use ptr; - use slice::MutableSlice; + use slice::{ImmutableSlice, MutableSlice}; /// A trait for operations on mutable `[u8]`s. pub trait MutableByteVector { @@ -1801,10 +1528,14 @@ pub mod bytes { /// `src` and `dst` must not overlap. Fails if the length of `dst` /// is less than the length of `src`. #[inline] - #[allow(deprecated)] pub fn copy_memory(dst: &mut [u8], src: &[u8]) { - // Bound checks are done at .copy_memory. - unsafe { dst.copy_memory(src) } + let len_src = src.len(); + assert!(dst.len() >= len_src); + unsafe { + ptr::copy_nonoverlapping_memory(dst.as_mut_ptr(), + src.as_ptr(), + len_src); + } } } |
