Skip to content

Commit

Permalink
Implement count for EscapeDefault and EscapeUnicode
Browse files Browse the repository at this point in the history
Trivial implementation, as both are `ExactSizeIterator`s.

Part of rust-lang#24214.
  • Loading branch information
ranma42 committed Jan 20, 2016
1 parent 7f5eae7 commit 009e243
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libcore/char.rs
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,11 @@ impl Iterator for EscapeUnicode {
let n = n + self.offset;
(n, Some(n))
}

#[inline]
fn count(self) -> usize {
self.len()
}
}

#[stable(feature = "rust1", since = "1.7.0")]
Expand Down Expand Up @@ -545,13 +550,9 @@ impl Iterator for EscapeDefault {
}
}

#[inline]
fn count(self) -> usize {
match self.state {
EscapeDefaultState::Char(_) => 1,
EscapeDefaultState::Unicode(iter) => iter.count(),
EscapeDefaultState::Done => 0,
EscapeDefaultState::Backslash(_) => 2,
}
self.len()
}

fn nth(&mut self, n: usize) -> Option<char> {
Expand Down

0 comments on commit 009e243

Please sign in to comment.