mirror of
https://github.com/rust-lang/rust
synced 2024-10-17 05:53:41 +00:00
Changes according to review
This commit is contained in:
parent
1e114a88bd
commit
acc876e42f
|
@ -52,21 +52,22 @@ pub(super) unsafe fn new(
|
|||
}
|
||||
}
|
||||
|
||||
// Only returns pointers to the slices, as that's
|
||||
// all we need to drop them. May only be called if `self.remaining != 0`.
|
||||
// Only returns pointers to the slices, as that's all we need
|
||||
// to drop them. May only be called if `self.remaining != 0`.
|
||||
unsafe fn as_slices(&self) -> (*mut [T], *mut [T]) {
|
||||
unsafe {
|
||||
let deque = self.deque.as_ref();
|
||||
|
||||
let start = self.idx;
|
||||
// We know that `self.idx + self.remaining <= deque.len <= usize::MAX`, so this won't overflow.
|
||||
let end = start + self.remaining;
|
||||
let logical_remaining_range = self.idx..self.idx + self.remaining;
|
||||
|
||||
// SAFETY: `start..end` represents the range of elements that
|
||||
// SAFETY: `logical_remaining_range` represents the
|
||||
// range into the logical buffer of elements that
|
||||
// haven't been drained yet, so they're all initialized,
|
||||
// and `slice::range(start..end, end) == start..end`,
|
||||
// so the preconditions for `slice_ranges` are met.
|
||||
let (a_range, b_range) = deque.slice_ranges(start..end, end);
|
||||
let (a_range, b_range) =
|
||||
deque.slice_ranges(logical_remaining_range.clone(), logical_remaining_range.end);
|
||||
(deque.buffer_range(a_range), deque.buffer_range(b_range))
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1230,10 +1230,9 @@ pub fn is_empty(&self) -> bool {
|
|||
/// # Safety
|
||||
///
|
||||
/// This function is always safe to call. For the resulting ranges to be valid
|
||||
/// ranges into the physical buffer, the caller must ensure that for all possible
|
||||
/// values of `range` and `len`, the result of calling `slice::range(range, ..len)`
|
||||
/// represents a valid range into the logical buffer, and that all elements
|
||||
/// in that range are initialized.
|
||||
/// ranges into the physical buffer, the caller must ensure that the result of
|
||||
/// calling `slice::range(range, ..len)` represents a valid range into the
|
||||
/// logical buffer, and that all elements in that range are initialized.
|
||||
fn slice_ranges<R>(&self, range: R, len: usize) -> (Range<usize>, Range<usize>)
|
||||
where
|
||||
R: RangeBounds<usize>,
|
||||
|
@ -1244,7 +1243,7 @@ fn slice_ranges<R>(&self, range: R, len: usize) -> (Range<usize>, Range<usize>)
|
|||
if len == 0 {
|
||||
(0..0, 0..0)
|
||||
} else {
|
||||
// `slice::range` guarantees that `start <= end <= self.len`.
|
||||
// `slice::range` guarantees that `start <= end <= len`.
|
||||
// because `len != 0`, we know that `start < end`, so `start < len`
|
||||
// and the indexing is valid.
|
||||
let wrapped_start = self.to_physical_idx(start);
|
||||
|
|
Loading…
Reference in a new issue