diff options
| author | Aaron Turon <aturon@mozilla.com> | 2014-10-02 11:47:38 -0700 |
|---|---|---|
| committer | Aaron Turon <aturon@mozilla.com> | 2014-10-02 11:47:38 -0700 |
| commit | 2f365ffdad40475e8f70f7af7f210d6c597b60f5 (patch) | |
| tree | 51154f8a256deb911f52558b4355fcb68bf2ea4e /src/libcore | |
| parent | b2d4eb186e99b66051be9089f836c66a558dd995 (diff) | |
| download | rust-2f365ffdad40475e8f70f7af7f210d6c597b60f5.tar.gz rust-2f365ffdad40475e8f70f7af7f210d6c597b60f5.zip | |
Revert "Review and rebasing changes"
This reverts commit 6e0611a48707a1f5d90aee32a02b2b15957ef25b.
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/slice.rs | 8 | ||||
| -rw-r--r-- | src/libcore/str.rs | 84 |
2 files changed, 28 insertions, 64 deletions
diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index a8becb315b2..2ff0fd2ef00 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -152,7 +152,7 @@ pub trait ImmutableSlice<'a, T> { fn tail(&self) -> &'a [T]; /// Returns all but the first `n' elements of a slice. - #[deprecated = "use slice_from"] + #[deprecated = "use slicing syntax"] fn tailn(&self, n: uint) -> &'a [T]; /// Returns all but the last element of a slice. @@ -161,6 +161,7 @@ pub trait ImmutableSlice<'a, T> { /// Returns all but the last `n' elements of a slice. #[deprecated = "use slice_to but note the arguments are different"] + #[deprecated = "use slicing syntax, 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. @@ -320,7 +321,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { fn tail(&self) -> &'a [T] { (*self)[1..] } #[inline] - #[deprecated = "use slice_from"] + #[deprecated = "use slicing syntax"] fn tailn(&self, n: uint) -> &'a [T] { (*self)[n..] } #[inline] @@ -329,7 +330,7 @@ impl<'a,T> ImmutableSlice<'a, T> for &'a [T] { } #[inline] - #[deprecated = "use slice_to but note the arguments are different"] + #[deprecated = "use slicing syntax but note the arguments are different"] fn initn(&self, n: uint) -> &'a [T] { (*self)[..self.len() - n] } @@ -542,6 +543,7 @@ pub trait MutableSlice<'a, T> { fn get_mut(self, index: uint) -> Option<&'a mut T>; /// Work with `self` as a mut slice. /// Primarily intended for getting a &mut [T] from a [T, ..N]. + #[deprecated = "use slicing syntax"] fn as_mut_slice(self) -> &'a mut [T]; /// Deprecated: use `iter_mut`. diff --git a/src/libcore/str.rs b/src/libcore/str.rs index 1c20d364bf8..f3a10a0a3ae 100644 --- a/src/libcore/str.rs +++ b/src/libcore/str.rs @@ -1164,7 +1164,6 @@ pub mod traits { fn equiv(&self, other: &S) -> bool { eq_slice(*self, other.as_slice()) } } - #[cfg(stage0)] impl ops::Slice<uint, str> for str { #[inline] fn as_slice_<'a>(&'a self) -> &'a str { @@ -1173,39 +1172,17 @@ pub mod traits { #[inline] fn slice_from_<'a>(&'a self, from: &uint) -> &'a str { - super::slice_from_impl(&self, *from) + self.slice_from(*from) } #[inline] fn slice_to_<'a>(&'a self, to: &uint) -> &'a str { - super::slice_to_impl(&self, *to) + self.slice_to(*to) } #[inline] fn slice_<'a>(&'a self, from: &uint, to: &uint) -> &'a str { - super::slice_impl(&self, *from, *to) - } - } - #[cfg(not(stage0))] - impl ops::Slice<uint, str> for str { - #[inline] - fn as_slice<'a>(&'a self) -> &'a str { - self - } - - #[inline] - fn slice_from<'a>(&'a self, from: &uint) -> &'a str { - super::slice_from_impl(&self, *from) - } - - #[inline] - fn slice_to<'a>(&'a self, to: &uint) -> &'a str { - super::slice_to_impl(&self, *to) - } - - #[inline] - fn slice<'a>(&'a self, from: &uint, to: &uint) -> &'a str { - super::slice_impl(&self, *from, *to) + self.slice(*from, *to) } } } @@ -1858,38 +1835,6 @@ fn slice_error_fail(s: &str, begin: uint, end: uint) -> ! { begin, end, s); } -#[inline] -fn slice_impl<'a>(this: &&'a str, begin: uint, end: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if begin <= end && - this.is_char_boundary(begin) && - this.is_char_boundary(end) { - unsafe { raw::slice_unchecked(*this, begin, end) } - } else { - slice_error_fail(*this, begin, end) - } -} - -#[inline] -fn slice_from_impl<'a>(this: &&'a str, begin: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if this.is_char_boundary(begin) { - unsafe { raw::slice_unchecked(*this, begin, this.len()) } - } else { - slice_error_fail(*this, begin, this.len()) - } -} - -#[inline] -fn slice_to_impl<'a>(this: &&'a str, end: uint) -> &'a str { - // is_char_boundary checks that the index is in [0, .len()] - if this.is_char_boundary(end) { - unsafe { raw::slice_unchecked(*this, 0, end) } - } else { - slice_error_fail(*this, 0, end) - } -} - impl<'a> StrSlice<'a> for &'a str { #[inline] fn contains<'a>(&self, needle: &'a str) -> bool { @@ -1993,17 +1938,34 @@ impl<'a> StrSlice<'a> for &'a str { #[inline] fn slice(&self, begin: uint, end: uint) -> &'a str { - slice_impl(self, begin, end) + // is_char_boundary checks that the index is in [0, .len()] + if begin <= end && + self.is_char_boundary(begin) && + self.is_char_boundary(end) { + unsafe { raw::slice_unchecked(*self, begin, end) } + } else { + slice_error_fail(*self, begin, end) + } } #[inline] fn slice_from(&self, begin: uint) -> &'a str { - slice_from_impl(self, begin) + // is_char_boundary checks that the index is in [0, .len()] + if self.is_char_boundary(begin) { + unsafe { raw::slice_unchecked(*self, begin, self.len()) } + } else { + slice_error_fail(*self, begin, self.len()) + } } #[inline] fn slice_to(&self, end: uint) -> &'a str { - slice_to_impl(self, end) + // is_char_boundary checks that the index is in [0, .len()] + if self.is_char_boundary(end) { + unsafe { raw::slice_unchecked(*self, 0, end) } + } else { + slice_error_fail(*self, 0, end) + } } fn slice_chars(&self, begin: uint, end: uint) -> &'a str { |
