Skip to content

Use len instead of size_hint where appropiate #34425

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libcollections/vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,7 +1658,7 @@ impl<T> Iterator for IntoIter<T> {

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

Expand Down
2 changes: 1 addition & 1 deletion src/libcore/fmt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1384,7 +1384,7 @@ impl Debug for str {
for (i, c) in self.char_indices() {
let esc = c.escape_default();
// If char needs escaping, flush backlog so far and write, else skip
if esc.size_hint() != (1, Some(1)) {
if esc.len() != 1 {
f.write_str(&self[from..i])?;
for c in esc {
f.write_char(c)?;
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/slice.rs
Original file line number Diff line number Diff line change
Expand Up @@ -835,7 +835,7 @@ macro_rules! iterator {

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

#[inline]
Expand Down Expand Up @@ -1444,7 +1444,7 @@ impl<'a, T> Iterator for Windows<'a, T> {

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

#[inline]
Expand Down Expand Up @@ -1541,7 +1541,7 @@ impl<'a, T> Iterator for Chunks<'a, T> {

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

#[inline]
Expand Down Expand Up @@ -1632,7 +1632,7 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {

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

#[inline]
Expand Down
9 changes: 4 additions & 5 deletions src/libcore/str/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ impl<'a> Iterator for Chars<'a> {

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let (len, _) = self.iter.size_hint();
let len = self.iter.len();
// `(len + 3)` can't overflow, because we know that the `slice::Iter`
// belongs to a slice in memory which has a maximum length of
// `isize::MAX` (that's well below `usize::MAX`).
Expand Down Expand Up @@ -480,12 +480,12 @@ impl<'a> Iterator for CharIndices<'a> {

#[inline]
fn next(&mut self) -> Option<(usize, char)> {
let (pre_len, _) = self.iter.iter.size_hint();
let pre_len = self.iter.iter.len();
match self.iter.next() {
None => None,
Some(ch) => {
let index = self.front_offset;
let (len, _) = self.iter.iter.size_hint();
let len = self.iter.iter.len();
self.front_offset += pre_len - len;
Some((index, ch))
}
Expand All @@ -505,8 +505,7 @@ impl<'a> DoubleEndedIterator for CharIndices<'a> {
match self.iter.next_back() {
None => None,
Some(ch) => {
let (len, _) = self.iter.iter.size_hint();
let index = self.front_offset + len;
let index = self.front_offset + self.iter.iter.len();
Some((index, ch))
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/libcore/str/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,9 +310,9 @@ unsafe impl<'a, C: CharEq> Searcher<'a> for CharEqSearcher<'a, C> {
let s = &mut self.char_indices;
// Compare lengths of the internal byte slice iterator
// to find length of current char
let (pre_len, _) = s.iter.iter.size_hint();
let pre_len = s.iter.iter.len();
if let Some((i, c)) = s.next() {
let (len, _) = s.iter.iter.size_hint();
let len = s.iter.iter.len();
let char_len = pre_len - len;
if self.char_eq.matches(c) {
return SearchStep::Match(i, i + char_len);
Expand All @@ -330,9 +330,9 @@ unsafe impl<'a, C: CharEq> ReverseSearcher<'a> for CharEqSearcher<'a, C> {
let s = &mut self.char_indices;
// Compare lengths of the internal byte slice iterator
// to find length of current char
let (pre_len, _) = s.iter.iter.size_hint();
let pre_len = s.iter.iter.len();
if let Some((i, c)) = s.next_back() {
let (len, _) = s.iter.iter.size_hint();
let len = s.iter.iter.len();
let char_len = pre_len - len;
if self.char_eq.matches(c) {
return SearchStep::Match(i, i + char_len);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/sys/common/wtf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ impl<'a> Iterator for Wtf8CodePoints<'a> {

#[inline]
fn size_hint(&self) -> (usize, Option<usize>) {
let (len, _) = self.bytes.size_hint();
let len = self.bytes.len();
(len.saturating_add(3) / 4, Some(len))
}
}
Expand Down