Skip to content

Commit b8abd55

Browse files
committed
Pull self.v.len() out in RChunks::next as suggested in review comments
1 parent b543816 commit b8abd55

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/core/src/slice/iter.rs

+7-6
Original file line numberDiff line numberDiff line change
@@ -2423,13 +2423,14 @@ impl<'a, T> Iterator for RChunks<'a, T> {
24232423
if self.v.is_empty() {
24242424
None
24252425
} else {
2426-
let chunksz = cmp::min(self.v.len(), self.chunk_size);
2426+
let len = self.v.len();
2427+
let chunksz = cmp::min(len, self.chunk_size);
24272428
// SAFETY: split_at_unchecked just requires the argument be less
2428-
// than the length. This could only happen if the expression
2429-
// `self.v.len() - chunksz` overflows. This could only happen if
2430-
// `chunksz > self.v.len()`, which is impossible as we initialize it
2431-
// as the `min` of `self.v.len()` and `self.chunk_size`.
2432-
let (fst, snd) = unsafe { self.v.split_at_unchecked(self.v.len() - chunksz) };
2429+
// than the length. This could only happen if the expression `len -
2430+
// chunksz` overflows. This could only happen if `chunksz > len`,
2431+
// which is impossible as we initialize it as the `min` of `len` and
2432+
// `self.chunk_size`.
2433+
let (fst, snd) = unsafe { self.v.split_at_unchecked(len - chunksz) };
24332434
self.v = fst;
24342435
Some(snd)
24352436
}

0 commit comments

Comments
 (0)