Skip to content

Commit 009e243

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

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
@@ -491,6 +491,11 @@ impl Iterator for EscapeUnicode {
491491
let n = n + self.offset;
492492
(n, Some(n))
493493
}
494+
495+
#[inline]
496+
fn count(self) -> usize {
497+
self.len()
498+
}
494499
}
495500

496501
#[stable(feature = "rust1", since = "1.7.0")]
@@ -545,13 +550,9 @@ impl Iterator for EscapeDefault {
545550
}
546551
}
547552

553+
#[inline]
548554
fn count(self) -> usize {
549-
match self.state {
550-
EscapeDefaultState::Char(_) => 1,
551-
EscapeDefaultState::Unicode(iter) => iter.count(),
552-
EscapeDefaultState::Done => 0,
553-
EscapeDefaultState::Backslash(_) => 2,
554-
}
555+
self.len()
555556
}
556557

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

0 commit comments

Comments
 (0)