Skip to content

Commit 03b1478

Browse files
committed
feat(allocator): add Allocator::end_ptr method
1 parent cb20b64 commit 03b1478

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

crates/oxc_allocator/src/from_raw_parts.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! * [`Allocator::alloc_bytes_start`]
55
//! * [`Allocator::data_ptr`]
66
//! * [`Allocator::set_data_ptr`]
7+
//! * [`Allocator::end_ptr`]
78
89
use std::{
910
alloc::Layout,
@@ -230,6 +231,15 @@ impl Allocator {
230231
chunk_footer.ptr.get()
231232
}
232233

234+
/// Get pointer end of this [`Allocator`]'s current chunk (after the `ChunkFooter`).
235+
pub fn end_ptr(&self) -> NonNull<u8> {
236+
// SAFETY: `chunk_footer_ptr` returns pointer to a valid `ChunkFooter`,
237+
// so stepping past it cannot be a out of bounds of the chunk's allocation.
238+
// If `Allocator` has not allocated, so `chunk_footer_ptr` returns a pointer to the static
239+
// empty chunk, it's still valid.
240+
unsafe { self.chunk_footer_ptr().add(1).cast::<u8>() }
241+
}
242+
233243
/// Get reference to current [`ChunkFooter`].
234244
///
235245
/// # SAFETY

0 commit comments

Comments
 (0)