Skip to content
Open
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
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1051,6 +1051,15 @@ impl AlignedBuf {
/// Creates a new buffer that is aligned with the simd register size
#[must_use]
pub fn with_capacity(capacity: usize) -> Self {
if capacity == 0 {
let layout = Layout::from_size_align(0, SIMDJSON_PADDING).unwrap();
return Self {
layout,
capacity: 0,
len: 0,
inner: NonNull::dangling(),
};
}
let Ok(layout) = Layout::from_size_align(capacity, SIMDJSON_PADDING) else {
Self::capacity_overflow()
};
Expand Down Expand Up @@ -1092,8 +1101,10 @@ impl AlignedBuf {
}
impl Drop for AlignedBuf {
fn drop(&mut self) {
unsafe {
dealloc(self.inner.as_ptr(), self.layout);
if self.capacity > 0 {
unsafe {
dealloc(self.inner.as_ptr(), self.layout);
}
}
}
}
Expand Down