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 #24214.
  • Loading branch information
ranma42 committed May 26, 2016
1 parent c30fa92 commit baa9680
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/libcore/char.rs
Expand Up @@ -470,6 +470,11 @@ impl Iterator for EscapeUnicode {
(n, Some(n))
}

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

fn last(self) -> Option<char> {
match self.state {
EscapeUnicodeState::Done => None,
Expand Down Expand Up @@ -535,13 +540,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 baa9680

Please sign in to comment.