diff options
| author | bors <bors@rust-lang.org> | 2015-04-16 03:22:21 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2015-04-16 03:22:21 +0000 |
| commit | 288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4 (patch) | |
| tree | 2606f4c9c39c215161feb41a74348d7e07d79c1c /src/libcore | |
| parent | e40449e0d545561c73a9b9b324b5971b533a87b7 (diff) | |
| parent | c55ae1dc3094912c935fb95cf915841af0259305 (diff) | |
| download | rust-288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4.tar.gz rust-288809c8f35d9b37f2e4f5c3ac168f56dbc3bbc4.zip | |
Auto merge of #23682 - tamird:DRY-is-empty, r=alexcrichton
r? @alexcrichton
Diffstat (limited to 'src/libcore')
| -rw-r--r-- | src/libcore/char.rs | 4 | ||||
| -rw-r--r-- | src/libcore/slice.rs | 18 | ||||
| -rw-r--r-- | src/libcore/str/mod.rs | 2 | ||||
| -rw-r--r-- | src/libcore/str/pattern.rs | 2 |
4 files changed, 13 insertions, 13 deletions
diff --git a/src/libcore/char.rs b/src/libcore/char.rs index ba9748eea71..740fa3eb19e 100644 --- a/src/libcore/char.rs +++ b/src/libcore/char.rs @@ -227,7 +227,7 @@ impl CharExt for char { #[inline] pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> { // Marked #[inline] to allow llvm optimizing it away - if code < MAX_ONE_B && dst.len() >= 1 { + if code < MAX_ONE_B && !dst.is_empty() { dst[0] = code as u8; Some(1) } else if code < MAX_TWO_B && dst.len() >= 2 { @@ -258,7 +258,7 @@ pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> { #[inline] pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> { // Marked #[inline] to allow llvm optimizing it away - if (ch & 0xFFFF) == ch && dst.len() >= 1 { + if (ch & 0xFFFF) == ch && !dst.is_empty() { // The BMP falls through (assuming non-surrogate, as it should) dst[0] = ch as u16; Some(1) diff --git a/src/libcore/slice.rs b/src/libcore/slice.rs index 0e6acf0160d..4b1742a4348 100644 --- a/src/libcore/slice.rs +++ b/src/libcore/slice.rs @@ -204,7 +204,7 @@ impl<T> SliceExt for [T] { #[inline] fn first(&self) -> Option<&T> { - if self.len() == 0 { None } else { Some(&self[0]) } + if self.is_empty() { None } else { Some(&self[0]) } } #[inline] @@ -217,7 +217,7 @@ impl<T> SliceExt for [T] { #[inline] fn last(&self) -> Option<&T> { - if self.len() == 0 { None } else { Some(&self[self.len() - 1]) } + if self.is_empty() { None } else { Some(&self[self.len() - 1]) } } #[inline] @@ -296,7 +296,7 @@ impl<T> SliceExt for [T] { #[inline] fn first_mut(&mut self) -> Option<&mut T> { - if self.len() == 0 { None } else { Some(&mut self[0]) } + if self.is_empty() { None } else { Some(&mut self[0]) } } #[inline] @@ -1306,7 +1306,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { #[inline] fn next(&mut self) -> Option<&'a [T]> { - if self.v.len() == 0 { + if self.v.is_empty() { None } else { let chunksz = cmp::min(self.v.len(), self.size); @@ -1318,7 +1318,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { - if self.v.len() == 0 { + if self.v.is_empty() { (0, Some(0)) } else { let n = self.v.len() / self.size; @@ -1333,7 +1333,7 @@ impl<'a, T> Iterator for Chunks<'a, T> { impl<'a, T> DoubleEndedIterator for Chunks<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a [T]> { - if self.v.len() == 0 { + if self.v.is_empty() { None } else { let remainder = self.v.len() % self.size; @@ -1384,7 +1384,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> { #[inline] fn next(&mut self) -> Option<&'a mut [T]> { - if self.v.len() == 0 { + if self.v.is_empty() { None } else { let sz = cmp::min(self.v.len(), self.chunk_size); @@ -1397,7 +1397,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> { #[inline] fn size_hint(&self) -> (usize, Option<usize>) { - if self.v.len() == 0 { + if self.v.is_empty() { (0, Some(0)) } else { let n = self.v.len() / self.chunk_size; @@ -1412,7 +1412,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> { impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> { #[inline] fn next_back(&mut self) -> Option<&'a mut [T]> { - if self.v.len() == 0 { + if self.v.is_empty() { None } else { let remainder = self.v.len() % self.chunk_size; diff --git a/src/libcore/str/mod.rs b/src/libcore/str/mod.rs index fc623f21167..2d6ef39361e 100644 --- a/src/libcore/str/mod.rs +++ b/src/libcore/str/mod.rs @@ -1119,7 +1119,7 @@ enum OldSearcher { impl OldSearcher { #[allow(dead_code)] fn new(haystack: &[u8], needle: &[u8]) -> OldSearcher { - if needle.len() == 0 { + if needle.is_empty() { // Handle specially unimplemented!() // FIXME: Tune this. diff --git a/src/libcore/str/pattern.rs b/src/libcore/str/pattern.rs index 62b693dcbe6..9a96612195c 100644 --- a/src/libcore/str/pattern.rs +++ b/src/libcore/str/pattern.rs @@ -457,7 +457,7 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher, { if m.state.done() { SearchStep::Done - } else if m.needle.len() == 0 && m.start <= m.end { + } else if m.needle.is_empty() && m.start <= m.end { // Case for needle == "" if let State::Reject(a, b) = m.state.take() { SearchStep::Reject(a, b) |
