Skip to content

Commit 288809c

Browse files
committed
Auto merge of #23682 - tamird:DRY-is-empty, r=alexcrichton
r? @alexcrichton
2 parents e40449e + c55ae1d commit 288809c

File tree

104 files changed

+262
-259
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+262
-259
lines changed

src/compiletest/compiletest.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ pub fn make_metrics_test_closure(config: &Config, testfile: &Path) -> test::Test
368368
fn extract_gdb_version(full_version_line: Option<String>) -> Option<String> {
369369
match full_version_line {
370370
Some(ref full_version_line)
371-
if full_version_line.trim().len() > 0 => {
371+
if !full_version_line.trim().is_empty() => {
372372
let full_version_line = full_version_line.trim();
373373

374374
// used to be a regex "(^|[^0-9])([0-9]\.[0-9])([^0-9]|$)"
@@ -408,7 +408,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
408408

409409
match full_version_line {
410410
Some(ref full_version_line)
411-
if full_version_line.trim().len() > 0 => {
411+
if !full_version_line.trim().is_empty() => {
412412
let full_version_line = full_version_line.trim();
413413

414414
for (pos, l) in full_version_line.char_indices() {
@@ -426,7 +426,7 @@ fn extract_lldb_version(full_version_line: Option<String>) -> Option<String> {
426426
let vers = full_version_line[pos + 5..].chars().take_while(|c| {
427427
c.is_digit(10)
428428
}).collect::<String>();
429-
if vers.len() > 0 { return Some(vers) }
429+
if !vers.is_empty() { return Some(vers) }
430430
}
431431
println!("Could not extract LLDB version from line '{}'",
432432
full_version_line);

src/compiletest/runtest.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
864864
}
865865
first = false;
866866
}
867-
if !failed && rest.len() == 0 {
867+
if !failed && rest.is_empty() {
868868
i += 1;
869869
}
870870
if i == num_check_lines {
@@ -1662,7 +1662,7 @@ fn _arm_push_aux_shared_library(config: &Config, testfile: &Path) {
16621662
// codegen tests (vs. clang)
16631663

16641664
fn append_suffix_to_stem(p: &Path, suffix: &str) -> PathBuf {
1665-
if suffix.len() == 0 {
1665+
if suffix.is_empty() {
16661666
p.to_path_buf()
16671667
} else {
16681668
let mut stem = p.file_stem().unwrap().to_os_string();

src/doc/reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3788,7 +3788,7 @@ its type parameters are types:
37883788

37893789
```ignore
37903790
fn map<A: Clone, B: Clone>(f: |A| -> B, xs: &[A]) -> Vec<B> {
3791-
if xs.len() == 0 {
3791+
if xs.is_empty() {
37923792
return vec![];
37933793
}
37943794
let first: B = f(xs[0].clone());

src/libcollections/btree/map.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -692,7 +692,7 @@ mod stack {
692692
// We've reached the root, so no matter what, we're done. We manually
693693
// access the root via the tree itself to avoid creating any dangling
694694
// pointers.
695-
if self.map.root.len() == 0 && !self.map.root.is_leaf() {
695+
if self.map.root.is_empty() && !self.map.root.is_leaf() {
696696
// We've emptied out the root, so make its only child the new root.
697697
// If it's a leaf, we just let it become empty.
698698
self.map.depth -= 1;

src/libcollections/btree/node.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,9 @@ impl <K, V> Node<K, V> {
585585
self._len
586586
}
587587

588+
/// Does the node not contain any key-value pairs
589+
pub fn is_empty(&self) -> bool { self.len() == 0 }
590+
588591
/// How many key-value pairs the node can fit
589592
pub fn capacity(&self) -> usize {
590593
self._capacity
@@ -1097,7 +1100,7 @@ impl<K, V> Node<K, V> {
10971100
/// When a node has no keys or values and only a single edge, extract that edge.
10981101
pub fn hoist_lone_child(&mut self) {
10991102
// Necessary for correctness, but in a private module
1100-
debug_assert!(self.len() == 0);
1103+
debug_assert!(self.is_empty());
11011104
debug_assert!(!self.is_leaf());
11021105

11031106
unsafe {
@@ -1225,7 +1228,7 @@ impl<K, V> Node<K, V> {
12251228
/// because we have one too many, and our parent now has one too few
12261229
fn split(&mut self) -> (K, V, Node<K, V>) {
12271230
// Necessary for correctness, but in a private function
1228-
debug_assert!(self.len() > 0);
1231+
debug_assert!(!self.is_empty());
12291232

12301233
let mut right = if self.is_leaf() {
12311234
Node::new_leaf(self.capacity())

src/libcore/char.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ impl CharExt for char {
227227
#[inline]
228228
pub fn encode_utf8_raw(code: u32, dst: &mut [u8]) -> Option<usize> {
229229
// Marked #[inline] to allow llvm optimizing it away
230-
if code < MAX_ONE_B && dst.len() >= 1 {
230+
if code < MAX_ONE_B && !dst.is_empty() {
231231
dst[0] = code as u8;
232232
Some(1)
233233
} 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> {
258258
#[inline]
259259
pub fn encode_utf16_raw(mut ch: u32, dst: &mut [u16]) -> Option<usize> {
260260
// Marked #[inline] to allow llvm optimizing it away
261-
if (ch & 0xFFFF) == ch && dst.len() >= 1 {
261+
if (ch & 0xFFFF) == ch && !dst.is_empty() {
262262
// The BMP falls through (assuming non-surrogate, as it should)
263263
dst[0] = ch as u16;
264264
Some(1)

src/libcore/slice.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ impl<T> SliceExt for [T] {
204204

205205
#[inline]
206206
fn first(&self) -> Option<&T> {
207-
if self.len() == 0 { None } else { Some(&self[0]) }
207+
if self.is_empty() { None } else { Some(&self[0]) }
208208
}
209209

210210
#[inline]
@@ -217,7 +217,7 @@ impl<T> SliceExt for [T] {
217217

218218
#[inline]
219219
fn last(&self) -> Option<&T> {
220-
if self.len() == 0 { None } else { Some(&self[self.len() - 1]) }
220+
if self.is_empty() { None } else { Some(&self[self.len() - 1]) }
221221
}
222222

223223
#[inline]
@@ -296,7 +296,7 @@ impl<T> SliceExt for [T] {
296296

297297
#[inline]
298298
fn first_mut(&mut self) -> Option<&mut T> {
299-
if self.len() == 0 { None } else { Some(&mut self[0]) }
299+
if self.is_empty() { None } else { Some(&mut self[0]) }
300300
}
301301

302302
#[inline]
@@ -1306,7 +1306,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13061306

13071307
#[inline]
13081308
fn next(&mut self) -> Option<&'a [T]> {
1309-
if self.v.len() == 0 {
1309+
if self.v.is_empty() {
13101310
None
13111311
} else {
13121312
let chunksz = cmp::min(self.v.len(), self.size);
@@ -1318,7 +1318,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13181318

13191319
#[inline]
13201320
fn size_hint(&self) -> (usize, Option<usize>) {
1321-
if self.v.len() == 0 {
1321+
if self.v.is_empty() {
13221322
(0, Some(0))
13231323
} else {
13241324
let n = self.v.len() / self.size;
@@ -1333,7 +1333,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {
13331333
impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
13341334
#[inline]
13351335
fn next_back(&mut self) -> Option<&'a [T]> {
1336-
if self.v.len() == 0 {
1336+
if self.v.is_empty() {
13371337
None
13381338
} else {
13391339
let remainder = self.v.len() % self.size;
@@ -1384,7 +1384,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
13841384

13851385
#[inline]
13861386
fn next(&mut self) -> Option<&'a mut [T]> {
1387-
if self.v.len() == 0 {
1387+
if self.v.is_empty() {
13881388
None
13891389
} else {
13901390
let sz = cmp::min(self.v.len(), self.chunk_size);
@@ -1397,7 +1397,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
13971397

13981398
#[inline]
13991399
fn size_hint(&self) -> (usize, Option<usize>) {
1400-
if self.v.len() == 0 {
1400+
if self.v.is_empty() {
14011401
(0, Some(0))
14021402
} else {
14031403
let n = self.v.len() / self.chunk_size;
@@ -1412,7 +1412,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
14121412
impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
14131413
#[inline]
14141414
fn next_back(&mut self) -> Option<&'a mut [T]> {
1415-
if self.v.len() == 0 {
1415+
if self.v.is_empty() {
14161416
None
14171417
} else {
14181418
let remainder = self.v.len() % self.chunk_size;

src/libcore/str/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ enum OldSearcher {
11191119
impl OldSearcher {
11201120
#[allow(dead_code)]
11211121
fn new(haystack: &[u8], needle: &[u8]) -> OldSearcher {
1122-
if needle.len() == 0 {
1122+
if needle.is_empty() {
11231123
// Handle specially
11241124
unimplemented!()
11251125
// FIXME: Tune this.

src/libcore/str/pattern.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -457,7 +457,7 @@ fn str_search_step<F, G>(mut m: &mut StrSearcher,
457457
{
458458
if m.state.done() {
459459
SearchStep::Done
460-
} else if m.needle.len() == 0 && m.start <= m.end {
460+
} else if m.needle.is_empty() && m.start <= m.end {
461461
// Case for needle == ""
462462
if let State::Reject(a, b) = m.state.take() {
463463
SearchStep::Reject(a, b)

src/libfmt_macros/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ impl<'a> Parser<'a> {
371371
None => {
372372
let tmp = self.cur.clone();
373373
match self.word() {
374-
word if word.len() > 0 => {
374+
word if !word.is_empty() => {
375375
if self.consume('$') {
376376
CountIsName(word)
377377
} else {
@@ -463,7 +463,7 @@ mod tests {
463463
fn musterr(s: &str) {
464464
let mut p = Parser::new(s);
465465
p.next();
466-
assert!(p.errors.len() != 0);
466+
assert!(!p.errors.is_empty());
467467
}
468468

469469
#[test]

0 commit comments

Comments
 (0)