Skip to content
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
19 changes: 10 additions & 9 deletions src/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ impl<Item, const INLINE: usize, const M: usize, Heap: Allocator>
unsafe {
this.set_len(0);
}
let ptr = this.as_ptr() as *const [Item; M];
let pointer = this.as_ptr() as *const [Item; M];
// SAFETY: these elements are initialized since the length was `M`
unsafe { Ok(ptr.read()) }
unsafe { Ok(pointer.read()) }
}
}
}
Expand Down Expand Up @@ -153,11 +153,11 @@ impl<Item, const INLINE: usize> From<<Vec<Item, Global> as Like>::Type>
let cap = vec.capacity();
// SAFETY: vec.capacity is not `0` (checked above), so the pointer
// can not dangle and thus specifically cannot be null.
let ptr = unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) };
let pointer = unsafe { NonNull::new_unchecked(vec.as_mut_ptr()) };

Self {
length: LocatedLength::new(length, true),
raw: RawSmallVec::heap(ptr, cap),
raw: RawSmallVec::heap(pointer, cap),
allocator: Global
}
}
Expand All @@ -184,15 +184,16 @@ impl<Item, const INLINE: usize, Heap: Allocator> From<SmallVec<Item, INLINE, Hea
} else {
let this = ManuallyDrop::new(this);
// SAFETY:
// - `ptr` was created with the SmallVec's allocator
// - `ptr` was created with the appropriate alignment for `Item`
// - the allocation pointed to by ptr is exactly cap * sizeof(Item)
// - `pointer` was created with the SmallVec's allocator
// - `pointer` was created with the appropriate alignment for `Item`
// - the allocation pointed to by pointer is exactly cap *
// sizeof(Item)
// - `length` is less than or equal to `cap`
// - the first `length` entries are proper `Item`-values
// - the allocation is not larger than `isize::MAX`
unsafe {
let (ptr, cap) = this.raw.heap;
<Vec<Item, Global> as Like>::Type::from_raw_parts(ptr.as_ptr(), length, cap)
let (pointer, cap) = this.raw.heap;
<Vec<Item, Global> as Like>::Type::from_raw_parts(pointer.as_ptr(), length, cap)
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/iterators/drain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ impl<'valid, Item: 'valid, const INLINE: usize, Heap: Allocator> Drop
let start = source_vec.len();
let tail = self.0.tail_start;
if tail != start {
let ptr = source_vec.as_mut_ptr();
let source = ptr.add(tail);
let destination = ptr.add(start);
let pointer = source_vec.as_mut_ptr();
let source = pointer.add(tail);
let destination = pointer.add(start);
copy(source, destination, self.0.tail_len);
}
source_vec.length.add(self.0.tail_len);
Expand Down Expand Up @@ -236,10 +236,10 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drain<'_, Item, INLINE, Heap> {

let new_tail_start = self.tail_start + additional;
unsafe {
let ptr = vec.as_mut_ptr();
let pointer = vec.as_mut_ptr();
copy(
ptr.add(self.tail_start),
ptr.add(new_tail_start),
pointer.add(self.tail_start),
pointer.add(new_tail_start),
self.tail_len
);
}
Expand Down
4 changes: 2 additions & 2 deletions src/iterators/extractif.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ where F: FnMut(&mut Item) -> bool
// backshift is required to prevent a
// double-drop of the last successfully
// drained item prior to a panic in the predicate.
let ptr = self.vec.as_mut_ptr();
let source = ptr.add(self.idx);
let pointer = self.vec.as_mut_ptr();
let source = pointer.add(self.idx);
let destination = source.sub(self.del);
let tail_len = self.old_len - self.idx;
source.copy_to(destination, tail_len);
Expand Down
22 changes: 11 additions & 11 deletions src/iterators/intoiter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ impl<Item, const INLINE: usize, Heap: Allocator> AsRef<[Item]> for IntoIter<Item
// `self.begin..end` are all initialized. So the pointer arithmetic is
// valid, and so is the construction of the slice
unsafe {
let ptr = self.raw.as_ptr(on_heap);
from_raw_parts(ptr.add(self.begin), end - self.begin)
let pointer = self.raw.as_ptr(on_heap);
from_raw_parts(pointer.add(self.begin), end - self.begin)
}
}
}
Expand All @@ -86,8 +86,8 @@ impl<Item, const INLINE: usize, Heap: Allocator> AsMut<[Item]> for IntoIter<Item
let (end, on_heap) = self.end.parts();
// SAFETY: see above
unsafe {
let ptr = self.raw.as_mut_ptr(on_heap);
from_raw_parts_mut(ptr.add(self.begin), end - self.begin)
let pointer = self.raw.as_mut_ptr(on_heap);
from_raw_parts_mut(pointer.add(self.begin), end - self.begin)
}
}
}
Expand Down Expand Up @@ -128,8 +128,8 @@ impl<Item, const INLINE: usize, Heap: Allocator> Iterator for IntoIter<Item, INL
} else {
// SAFETY: see above
unsafe {
let ptr = self.raw.as_mut_ptr(on_heap);
let value = ptr.add(self.begin).read();
let pointer = self.raw.as_mut_ptr(on_heap);
let value = pointer.add(self.begin).read();
self.begin += 1;
Some(value)
}
Expand All @@ -154,9 +154,9 @@ impl<Item, const INLINE: usize, Heap: Allocator> DoubleEndedIterator
} else {
// SAFETY: see above
unsafe {
let ptr = self.raw.as_mut_ptr(on_heap);
let pointer = self.raw.as_mut_ptr(on_heap);
self.end.sub(1);
let value = ptr.add(end - 1).read();
let value = pointer.add(end - 1).read();
Some(value)
}
}
Expand All @@ -175,19 +175,19 @@ impl<Item, const INLINE: usize, Heap: Allocator> Drop for IntoIter<Item, INLINE,
unsafe {
let (end, on_heap) = self.end.parts();
let begin = self.begin;
let ptr = self.raw.as_mut_ptr(on_heap);
let pointer = self.raw.as_mut_ptr(on_heap);
let _drop_dealloc = if on_heap {
let capacity = self.raw.heap.1;
Some(DropDealloc {
ptr: NonNull::new_unchecked(ptr as *mut u8),
pointer: NonNull::new_unchecked(pointer as *mut u8),
size_bytes: capacity * size_of::<Item>(),
align: align_of::<Item>(),
allocator: &self.allocator
})
} else {
None
};
slice_from_raw_parts_mut(ptr.add(begin), end - begin).drop_in_place();
slice_from_raw_parts_mut(pointer.add(begin), end - begin).drop_in_place();
}
}
}
Expand Down
Loading
Loading