about summary refs log tree commit diff
path: root/src/libcore/slice.rs
diff options
context:
space:
mode:
authorBrian Anderson <banderson@mozilla.com>2015-01-24 09:15:42 -0800
committerBrian Anderson <banderson@mozilla.com>2015-01-25 01:20:55 -0800
commit63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70 (patch)
treec732033c0822f25f2aebcdf193de1b257bac1855 /src/libcore/slice.rs
parentb44ee371b8beea77aa1364460acbba14a8516559 (diff)
parent0430a43d635841db44978bb648e9cf7e7cfa1bba (diff)
downloadrust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.tar.gz
rust-63fcbcf3ce8f0ca391c18b2d61833ae6beb3ac70.zip
Merge remote-tracking branch 'rust-lang/master'
Conflicts:
	mk/tests.mk
	src/liballoc/arc.rs
	src/liballoc/boxed.rs
	src/liballoc/rc.rs
	src/libcollections/bit.rs
	src/libcollections/btree/map.rs
	src/libcollections/btree/set.rs
	src/libcollections/dlist.rs
	src/libcollections/ring_buf.rs
	src/libcollections/slice.rs
	src/libcollections/str.rs
	src/libcollections/string.rs
	src/libcollections/vec.rs
	src/libcollections/vec_map.rs
	src/libcore/any.rs
	src/libcore/array.rs
	src/libcore/borrow.rs
	src/libcore/error.rs
	src/libcore/fmt/mod.rs
	src/libcore/iter.rs
	src/libcore/marker.rs
	src/libcore/ops.rs
	src/libcore/result.rs
	src/libcore/slice.rs
	src/libcore/str/mod.rs
	src/libregex/lib.rs
	src/libregex/re.rs
	src/librustc/lint/builtin.rs
	src/libstd/collections/hash/map.rs
	src/libstd/collections/hash/set.rs
	src/libstd/sync/mpsc/mod.rs
	src/libstd/sync/mutex.rs
	src/libstd/sync/poison.rs
	src/libstd/sync/rwlock.rs
	src/libsyntax/feature_gate.rs
	src/libsyntax/test.rs
Diffstat (limited to 'src/libcore/slice.rs')
-rw-r--r--src/libcore/slice.rs81
1 files changed, 27 insertions, 54 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs
index 9f44fe96126..2b682111781 100644
--- a/src/libcore/slice.rs
+++ b/src/libcore/slice.rs
@@ -67,9 +67,6 @@ use raw::Slice as RawSlice;
 pub trait SliceExt {
     type Item;
 
-    fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [Self::Item];
-    fn slice_from<'a>(&'a self, start: uint) -> &'a [Self::Item];
-    fn slice_to<'a>(&'a self, end: uint) -> &'a [Self::Item];
     fn split_at<'a>(&'a self, mid: uint) -> (&'a [Self::Item], &'a [Self::Item]);
     fn iter<'a>(&'a self) -> Iter<'a, Self::Item>;
     fn split<'a, P>(&'a self, pred: P) -> Split<'a, Self::Item, P>
@@ -93,9 +90,6 @@ pub trait SliceExt {
     fn is_empty(&self) -> bool { self.len() == 0 }
     fn get_mut<'a>(&'a mut self, index: uint) -> Option<&'a mut Self::Item>;
     fn as_mut_slice<'a>(&'a mut self) -> &'a mut [Self::Item];
-    fn slice_mut<'a>(&'a mut self, start: uint, end: uint) -> &'a mut [Self::Item];
-    fn slice_from_mut<'a>(&'a mut self, start: uint) -> &'a mut [Self::Item];
-    fn slice_to_mut<'a>(&'a mut self, end: uint) -> &'a mut [Self::Item];
     fn iter_mut<'a>(&'a mut self) -> IterMut<'a, Self::Item>;
     fn first_mut<'a>(&'a mut self) -> Option<&'a mut Self::Item>;
     fn tail_mut<'a>(&'a mut self) -> &'a mut [Self::Item];
@@ -136,28 +130,6 @@ impl<T> SliceExt for [T] {
     type Item = T;
 
     #[inline]
-    fn slice(&self, start: uint, end: uint) -> &[T] {
-        assert!(start <= end);
-        assert!(end <= self.len());
-        unsafe {
-            transmute(RawSlice {
-                data: self.as_ptr().offset(start as int),
-                len: (end - start)
-            })
-        }
-    }
-
-    #[inline]
-    fn slice_from(&self, start: uint) -> &[T] {
-        self.slice(start, self.len())
-    }
-
-    #[inline]
-    fn slice_to(&self, end: uint) -> &[T] {
-        self.slice(0, end)
-    }
-
-    #[inline]
     fn split_at(&self, mid: uint) -> (&[T], &[T]) {
         (&self[..mid], &self[mid..])
     }
@@ -240,7 +212,7 @@ impl<T> SliceExt for [T] {
 
     #[inline]
     fn init(&self) -> &[T] {
-        &self[..(self.len() - 1)]
+        &self[..self.len() - 1]
     }
 
     #[inline]
@@ -291,20 +263,6 @@ impl<T> SliceExt for [T] {
     #[inline]
     fn as_mut_slice(&mut self) -> &mut [T] { self }
 
-    fn slice_mut(&mut self, start: uint, end: uint) -> &mut [T] {
-        ops::IndexMut::index_mut(self, &ops::Range { start: start, end: end } )
-    }
-
-    #[inline]
-    fn slice_from_mut(&mut self, start: uint) -> &mut [T] {
-        ops::IndexMut::index_mut(self, &ops::RangeFrom { start: start } )
-    }
-
-    #[inline]
-    fn slice_to_mut(&mut self, end: uint) -> &mut [T] {
-        ops::IndexMut::index_mut(self, &ops::RangeTo { end: end } )
-    }
-
     #[inline]
     fn split_at_mut(&mut self, mid: uint) -> (&mut [T], &mut [T]) {
         unsafe {
@@ -345,13 +303,13 @@ impl<T> SliceExt for [T] {
 
     #[inline]
     fn tail_mut(&mut self) -> &mut [T] {
-        self.slice_from_mut(1)
+        &mut self[1 ..]
     }
 
     #[inline]
     fn init_mut(&mut self) -> &mut [T] {
         let len = self.len();
-        self.slice_to_mut(len-1)
+        &mut self[.. (len - 1)]
     }
 
     #[inline]
@@ -449,7 +407,7 @@ impl<T> SliceExt for [T] {
     #[inline]
     fn ends_with(&self, needle: &[T]) -> bool where T: PartialEq {
         let (m, n) = (self.len(), needle.len());
-        m >= n && needle == &self[(m-n)..]
+        m >= n && needle == &self[m-n..]
     }
 
     #[unstable(feature = "core")]
@@ -483,7 +441,7 @@ impl<T> SliceExt for [T] {
         self.swap(j, i-1);
 
         // Step 4: Reverse the (previously) weakly decreasing part
-        self.slice_from_mut(i).reverse();
+        self[i..].reverse();
 
         true
     }
@@ -505,7 +463,7 @@ impl<T> SliceExt for [T] {
         }
 
         // Step 2: Reverse the weakly increasing part
-        self.slice_from_mut(i).reverse();
+        self[i..].reverse();
 
         // Step 3: Find the rightmost element equal to or bigger than the pivot (i-1)
         let mut j = self.len() - 1;
@@ -522,8 +480,8 @@ impl<T> SliceExt for [T] {
     #[inline]
     fn clone_from_slice(&mut self, src: &[T]) -> uint where T: Clone {
         let min = cmp::min(self.len(), src.len());
-        let dst = self.slice_to_mut(min);
-        let src = src.slice_to(min);
+        let dst = &mut self[.. min];
+        let src = &src[.. min];
         for i in range(0, min) {
             dst[i].clone_from(&src[i]);
         }
@@ -531,6 +489,7 @@ impl<T> SliceExt for [T] {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::Index<uint> for [T] {
     type Output = T;
 
@@ -541,6 +500,7 @@ impl<T> ops::Index<uint> for [T] {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::IndexMut<uint> for [T] {
     type Output = T;
 
@@ -551,6 +511,7 @@ impl<T> ops::IndexMut<uint> for [T] {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::Index<ops::Range<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -565,6 +526,7 @@ impl<T> ops::Index<ops::Range<uint>> for [T] {
         }
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -572,6 +534,7 @@ impl<T> ops::Index<ops::RangeTo<uint>> for [T] {
         self.index(&ops::Range{ start: 0, end: index.end })
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -579,6 +542,7 @@ impl<T> ops::Index<ops::RangeFrom<uint>> for [T] {
         self.index(&ops::Range{ start: index.start, end: self.len() })
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::Index<ops::FullRange> for [T] {
     type Output = [T];
     #[inline]
@@ -587,6 +551,7 @@ impl<T> ops::Index<ops::FullRange> for [T] {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -601,6 +566,7 @@ impl<T> ops::IndexMut<ops::Range<uint>> for [T] {
         }
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -608,6 +574,7 @@ impl<T> ops::IndexMut<ops::RangeTo<uint>> for [T] {
         self.index_mut(&ops::Range{ start: 0, end: index.end })
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
     type Output = [T];
     #[inline]
@@ -616,6 +583,7 @@ impl<T> ops::IndexMut<ops::RangeFrom<uint>> for [T] {
         self.index_mut(&ops::Range{ start: index.start, end: len })
     }
 }
+#[stable(feature = "rust1", since = "1.0.0")]
 impl<T> ops::IndexMut<ops::FullRange> for [T] {
     type Output = [T];
     #[inline]
@@ -974,7 +942,7 @@ impl<'a, T, P> Iterator for Split<'a, T, P> where P: FnMut(&T) -> bool {
             None => self.finish(),
             Some(idx) => {
                 let ret = Some(&self.v[..idx]);
-                self.v = &self.v[(idx + 1)..];
+                self.v = &self.v[idx + 1..];
                 ret
             }
         }
@@ -999,7 +967,7 @@ impl<'a, T, P> DoubleEndedIterator for Split<'a, T, P> where P: FnMut(&T) -> boo
         match self.v.iter().rposition(|x| (self.pred)(x)) {
             None => self.finish(),
             Some(idx) => {
-                let ret = Some(&self.v[(idx + 1)..]);
+                let ret = Some(&self.v[idx + 1..]);
                 self.v = &self.v[..idx];
                 ret
             }
@@ -1052,7 +1020,7 @@ impl<'a, T, P> Iterator for SplitMut<'a, T, P> where P: FnMut(&T) -> bool {
             Some(idx) => {
                 let tmp = mem::replace(&mut self.v, &mut []);
                 let (head, tail) = tmp.split_at_mut(idx);
-                self.v = tail.slice_from_mut(1);
+                self.v = &mut tail[1..];
                 Some(head)
             }
         }
@@ -1088,7 +1056,7 @@ impl<'a, T, P> DoubleEndedIterator for SplitMut<'a, T, P> where
                 let tmp = mem::replace(&mut self.v, &mut []);
                 let (head, tail) = tmp.split_at_mut(idx);
                 self.v = head;
-                Some(tail.slice_from_mut(1))
+                Some(&mut tail[1..])
             }
         }
     }
@@ -1270,6 +1238,9 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a, T> ExactSizeIterator for Chunks<'a, T> {}
+
 #[unstable(feature = "core", reason = "trait is experimental")]
 impl<'a, T> RandomAccessIterator for Chunks<'a, T> {
     #[inline]
@@ -1348,6 +1319,8 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
     }
 }
 
+#[stable(feature = "rust1", since = "1.0.0")]
+impl<'a, T> ExactSizeIterator for ChunksMut<'a, T> {}
 
 //
 // Free functions