Skip to content

Commit 9f18d10

Browse files
committed
rename and export start_ptr()/mut to as_ptr()/mut
This makes it comply with the std Vec's API
1 parent 4cde654 commit 9f18d10

1 file changed

Lines changed: 17 additions & 17 deletions

File tree

src/lib.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,12 @@ impl<H, T> HeaderVec<H, T> {
162162

163163
#[inline(always)]
164164
pub fn as_slice(&self) -> &[T] {
165-
unsafe { core::slice::from_raw_parts(self.start_ptr(), self.len_strict()) }
165+
unsafe { core::slice::from_raw_parts(self.as_ptr(), self.len_strict()) }
166166
}
167167

168168
#[inline(always)]
169169
pub fn as_mut_slice(&mut self) -> &mut [T] {
170-
unsafe { core::slice::from_raw_parts_mut(self.start_ptr_mut(), self.len_exact()) }
170+
unsafe { core::slice::from_raw_parts_mut(self.as_mut_ptr(), self.len_exact()) }
171171
}
172172

173173
/// This is useful to check if two nodes are the same. Use it with [`HeaderVec::is`].
@@ -180,7 +180,7 @@ impl<H, T> HeaderVec<H, T> {
180180
/// This is useful for updating weak references after [`HeaderVec::push`] returns the pointer.
181181
#[inline(always)]
182182
pub fn is(&self, ptr: *const ()) -> bool {
183-
self.ptr.as_ptr() as *const () == ptr
183+
self.ptr() == ptr
184184
}
185185

186186
/// Create a (dangerous) weak reference to the `HeaderVec`. This is useful to be able
@@ -301,7 +301,7 @@ impl<H, T> HeaderVec<H, T> {
301301
// Reallocate the pointer.
302302
let ptr = unsafe {
303303
alloc::alloc::realloc(
304-
self.ptr.as_ptr() as *mut u8,
304+
self.ptr() as *mut u8,
305305
Self::layout(old_capacity),
306306
Self::elems_to_mem_bytes(new_capacity),
307307
) as *mut AlignedHeader<H, T>
@@ -336,7 +336,7 @@ impl<H, T> HeaderVec<H, T> {
336336
let new_len = old_len + 1;
337337
let previous_pointer = self.reserve(1);
338338
unsafe {
339-
core::ptr::write(self.start_ptr_mut().add(old_len), item);
339+
core::ptr::write(self.as_mut_ptr().add(old_len), item);
340340
}
341341
self.header_mut().len = new_len.into();
342342
previous_pointer
@@ -353,7 +353,7 @@ impl<H, T> HeaderVec<H, T> {
353353
let mut head = 0;
354354
let original_len = self.len_exact();
355355
// Get the offset of the beginning of the slice.
356-
let start_ptr = self.start_ptr_mut();
356+
let start_ptr = self.as_mut_ptr();
357357
// Go through each index.
358358
for index in 0..original_len {
359359
unsafe {
@@ -444,33 +444,33 @@ impl<H, T> HeaderVec<H, T> {
444444

445445
/// Gets the pointer to the start of the slice.
446446
#[inline(always)]
447-
fn start_ptr(&self) -> *const T {
448-
unsafe { (self.ptr.as_ptr() as *const T).add(Self::offset()) }
447+
pub fn as_ptr(&self) -> *const T {
448+
unsafe { (self.ptr() as *const T).add(Self::offset()) }
449449
}
450450

451451
/// Gets the pointer to the start of the slice.
452452
#[inline(always)]
453-
fn start_ptr_mut(&mut self) -> *mut T {
454-
unsafe { (self.ptr.as_ptr() as *mut T).add(Self::offset()) }
453+
pub fn as_mut_ptr(&mut self) -> *mut T {
454+
unsafe { (self.ptr() as *mut T).add(Self::offset()) }
455455
}
456456

457457
/// Gets the pointer to the end of the slice. This returns a mutable pointer to
458458
/// uninitialized memory behind the last element.
459459
#[inline(always)]
460460
fn end_ptr_mut(&mut self) -> *mut T {
461-
unsafe { self.start_ptr_mut().add(self.len_exact()) }
461+
unsafe { self.as_mut_ptr().add(self.len_exact()) }
462462
}
463463

464464
#[inline(always)]
465465
fn header(&self) -> &HeaderVecHeader<H> {
466466
// The beginning of the memory is always the header.
467-
unsafe { &*(self.ptr.as_ptr() as *const HeaderVecHeader<H>) }
467+
unsafe { &*(self.ptr() as *const HeaderVecHeader<H>) }
468468
}
469469

470470
#[inline(always)]
471471
fn header_mut(&mut self) -> &mut HeaderVecHeader<H> {
472472
// The beginning of the memory is always the header.
473-
unsafe { &mut *(self.ptr.as_ptr() as *mut HeaderVecHeader<H>) }
473+
unsafe { &mut *(self.ptr() as *mut HeaderVecHeader<H>) }
474474
}
475475
}
476476

@@ -532,14 +532,14 @@ impl<H, T> HeaderVec<H, T> {
532532

533533
#[inline(always)]
534534
pub fn as_slice_atomic_acquire(&self) -> &[T] {
535-
unsafe { core::slice::from_raw_parts(self.start_ptr(), self.len_atomic_acquire()) }
535+
unsafe { core::slice::from_raw_parts(self.as_ptr(), self.len_atomic_acquire()) }
536536
}
537537

538538
/// Gets the pointer to the end of the slice. This returns a mutable pointer to
539539
/// uninitialized memory behind the last element.
540540
#[inline(always)]
541541
fn end_ptr_atomic_mut(&self) -> *mut T {
542-
unsafe { self.start_ptr().add(self.len_atomic_acquire()) as *mut T }
542+
unsafe { self.as_ptr().add(self.len_atomic_acquire()) as *mut T }
543543
}
544544

545545
/// Atomically adds an item to the end of the list without reallocation.
@@ -609,9 +609,9 @@ impl<H, T> Drop for HeaderVec<H, T> {
609609
unsafe {
610610
ptr::drop_in_place(&mut self.header_mut().head);
611611
for ix in 0..self.len_exact() {
612-
ptr::drop_in_place(self.start_ptr_mut().add(ix));
612+
ptr::drop_in_place(self.as_mut_ptr().add(ix));
613613
}
614-
alloc::alloc::dealloc(self.ptr.as_ptr() as *mut u8, Self::layout(self.capacity()));
614+
alloc::alloc::dealloc(self.ptr() as *mut u8, Self::layout(self.capacity()));
615615
}
616616
}
617617
}

0 commit comments

Comments
 (0)