Skip to content
This repository has been archived by the owner on Feb 14, 2023. It is now read-only.

The scope of the unsafe block can be appropriately reduced #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
8 changes: 4 additions & 4 deletions src/buffer/slice_deque_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ impl SliceDequeBuf {
}

pub fn consume(&mut self, amt: usize) {
let offset = cmp::min(amt, self.len()) as isize;
if offset < 0 {
panic!("BufImpl.consume() arg overflowed isize: {:x}", amt)
}
unsafe {
let offset = cmp::min(amt, self.len()) as isize;

if offset < 0 {
panic!("BufImpl.consume() arg overflowed isize: {:x}", amt)
}

self.deque.move_head(offset);
}
Expand Down
2 changes: 1 addition & 1 deletion src/buffer/std_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ mod impl_ {

buf.reserve_exact(additional);

let new_cap = buf.capacity();
unsafe {
let new_cap = buf.capacity();
buf.set_len(new_cap);
}

Expand Down
10 changes: 5 additions & 5 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1038,10 +1038,10 @@ impl Buffer {

let cap = self.capacity();
if self.zeroed < cap {
unsafe {
let buf = self.buf.write_buf();

let buf = unsafe { self.buf.write_buf() };
init_buffer(&rdr, buf);
}


self.zeroed = cap;
}
Expand All @@ -1064,8 +1064,8 @@ impl Buffer {
/// it will fill the usable space and return the number of bytes copied. If there is no usable
/// space, this returns 0.
pub fn copy_from_slice(&mut self, src: &[u8]) -> usize {
let len = unsafe {
let mut buf = self.buf.write_buf();
let len = {
let mut buf = unsafe { self.buf.write_buf() };
let len = cmp::min(buf.len(), src.len());
buf[..len].copy_from_slice(&src[..len]);
len
Expand Down