Issue 3223: reformat via cargo fmt
This commit is contained in:
12
src/arena.rs
12
src/arena.rs
@@ -496,12 +496,12 @@ impl Arena {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>, tag: ArenaHeaderTag) {
|
unsafe fn drop_slab_in_place(value: NonNull<AllocSlab>, tag: ArenaHeaderTag) {
|
||||||
macro_rules! drop_typed_slab_in_place {
|
macro_rules! drop_typed_slab_in_place {
|
||||||
($payload: ty, $value: expr) => {
|
($payload: ty, $value: expr) => {
|
||||||
<$payload as ArenaAllocated>::dealloc($value.cast::<TypedAllocSlab<$payload>>())
|
<$payload as ArenaAllocated>::dealloc($value.cast::<TypedAllocSlab<$payload>>())
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
match tag {
|
match tag {
|
||||||
ArenaHeaderTag::Integer => {
|
ArenaHeaderTag::Integer => {
|
||||||
|
|||||||
@@ -58,20 +58,20 @@ struct InnerHeap {
|
|||||||
|
|
||||||
impl InnerHeap {
|
impl InnerHeap {
|
||||||
unsafe fn grow(&mut self) -> bool {
|
unsafe fn grow(&mut self) -> bool {
|
||||||
let new_cap = if self.byte_cap == 0 {
|
let new_cap = if self.byte_cap == 0 {
|
||||||
256 * 256 * 8
|
256 * 256 * 8
|
||||||
} else {
|
} else {
|
||||||
2 * self.byte_cap
|
2 * self.byte_cap
|
||||||
};
|
};
|
||||||
|
|
||||||
let new_layout =
|
let new_layout =
|
||||||
alloc::Layout::from_size_align(new_cap, size_of::<HeapCellValue>()).unwrap();
|
alloc::Layout::from_size_align(new_cap, size_of::<HeapCellValue>()).unwrap();
|
||||||
|
|
||||||
assert!(
|
assert!(
|
||||||
new_layout.size() <= isize::MAX as usize,
|
new_layout.size() <= isize::MAX as usize,
|
||||||
"Allocation too large. We should probably GC (TODO)"
|
"Allocation too large. We should probably GC (TODO)"
|
||||||
);
|
);
|
||||||
unsafe {
|
unsafe {
|
||||||
let new_ptr = if self.byte_cap == 0 {
|
let new_ptr = if self.byte_cap == 0 {
|
||||||
alloc::alloc(new_layout)
|
alloc::alloc(new_layout)
|
||||||
} else {
|
} else {
|
||||||
@@ -104,12 +104,12 @@ pub struct HeapStringScan<'a> {
|
|||||||
|
|
||||||
// The heap_slice should be inside the heap
|
// The heap_slice should be inside the heap
|
||||||
unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> {
|
unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> {
|
||||||
let string_len = heap_slice
|
let string_len = heap_slice
|
||||||
.iter()
|
.iter()
|
||||||
.position(|b| *b == 0u8)
|
.position(|b| *b == 0u8)
|
||||||
.unwrap_or(heap_slice.len());
|
.unwrap_or(heap_slice.len());
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
let zero_byte_addr = heap_slice.as_ptr().add(string_len);
|
let zero_byte_addr = heap_slice.as_ptr().add(string_len);
|
||||||
|
|
||||||
let sentinel_len = pstr_sentinel_length(zero_byte_addr.addr());
|
let sentinel_len = pstr_sentinel_length(zero_byte_addr.addr());
|
||||||
@@ -130,19 +130,19 @@ unsafe fn scan_slice_to_str(heap_slice: &[u8]) -> HeapStringScan<'_> {
|
|||||||
// Same as scan_slice_to_str but assumes that the slice is from the start of a string.
|
// Same as scan_slice_to_str but assumes that the slice is from the start of a string.
|
||||||
// Can be used on strings out of the heap.
|
// Can be used on strings out of the heap.
|
||||||
unsafe fn scan_slice_to_str_from_start(heap_slice: &[u8]) -> HeapStringScan<'_> {
|
unsafe fn scan_slice_to_str_from_start(heap_slice: &[u8]) -> HeapStringScan<'_> {
|
||||||
let string_len = heap_slice
|
let string_len = heap_slice
|
||||||
.iter()
|
.iter()
|
||||||
.position(|b| *b == 0u8)
|
.position(|b| *b == 0u8)
|
||||||
.unwrap_or(heap_slice.len());
|
.unwrap_or(heap_slice.len());
|
||||||
|
|
||||||
let sentinel_len = pstr_sentinel_length(string_len);
|
let sentinel_len = pstr_sentinel_length(string_len);
|
||||||
let tail_idx = cell_index!(
|
let tail_idx = cell_index!(
|
||||||
(string_len + sentinel_len).next_multiple_of(ALIGN)
|
(string_len + sentinel_len).next_multiple_of(ALIGN)
|
||||||
+ if sentinel_len <= 1 { heap_index!(1) } else { 0 }
|
+ if sentinel_len <= 1 { heap_index!(1) } else { 0 }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let str_slice = &heap_slice[..string_len];
|
||||||
|
|
||||||
let str_slice = &heap_slice[..string_len];
|
|
||||||
|
|
||||||
unsafe {
|
unsafe {
|
||||||
HeapStringScan {
|
HeapStringScan {
|
||||||
string: std::str::from_utf8_unchecked(str_slice),
|
string: std::str::from_utf8_unchecked(str_slice),
|
||||||
|
|||||||
@@ -176,8 +176,8 @@ impl Stack {
|
|||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
unsafe fn alloc(&mut self, frame_size: usize) -> Result<NonNull<u8>, AllocError> {
|
unsafe fn alloc(&mut self, frame_size: usize) -> Result<NonNull<u8>, AllocError> {
|
||||||
loop {
|
loop {
|
||||||
unsafe {
|
unsafe {
|
||||||
let ptr = self.buf.alloc(frame_size);
|
let ptr = self.buf.alloc(frame_size);
|
||||||
if let Some(ptr) = NonNull::new(ptr) {
|
if let Some(ptr) = NonNull::new(ptr) {
|
||||||
return Ok(ptr);
|
return Ok(ptr);
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ pub(crate) fn set_prompt(value: bool) {
|
|||||||
#[cfg(feature = "repl")]
|
#[cfg(feature = "repl")]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn get_prompt() -> &'static str {
|
fn get_prompt() -> &'static str {
|
||||||
if unsafe { PROMPT } { "?- " } else { "" }
|
if unsafe { PROMPT } { "?- " } else { "" }
|
||||||
}
|
}
|
||||||
|
|
||||||
thread_local! {
|
thread_local! {
|
||||||
|
|||||||
Reference in New Issue
Block a user