Skip to content

Commit baa9680

Browse files
committed
Implement count for EscapeDefault and EscapeUnicode
Trivial implementation, as both are `ExactSizeIterator`s. Part of rust-lang#24214.
1 parent c30fa92 commit baa9680

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

src/libcore/char.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ impl Iterator for EscapeUnicode {
470470
(n, Some(n))
471471
}
472472

473+
#[inline]
474+
fn count(self) -> usize {
475+
self.len()
476+
}
477+
473478
fn last(self) -> Option<char> {
474479
match self.state {
475480
EscapeUnicodeState::Done => None,
@@ -535,13 +540,9 @@ impl Iterator for EscapeDefault {
535540
}
536541
}
537542

543+
#[inline]
538544
fn count(self) -> usize {
539-
match self.state {
540-
EscapeDefaultState::Char(_) => 1,
541-
EscapeDefaultState::Unicode(iter) => iter.count(),
542-
EscapeDefaultState::Done => 0,
543-
EscapeDefaultState::Backslash(_) => 2,
544-
}
545+
self.len()
545546
}
546547

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

0 commit comments

Comments
 (0)