Skip to content

Commit

Permalink
chore: fix clippy (assume_init_ref/mut)
Browse files Browse the repository at this point in the history
  • Loading branch information
byeongkeunahn committed Jan 20, 2025
1 parent aff8a9b commit 975634a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
12 changes: 4 additions & 8 deletions basm-std/src/platform/io/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ impl<const N: usize> Reader<N> {
if white_cnt == 0 {
/* No whitespace has been found. We have to read.
* We try to read as much as possible at once. */
rem += services::read_stdio(
0,
MaybeUninit::slice_assume_init_mut(&mut self.buf[rem..Self::BUF_LEN]),
);
rem += services::read_stdio(0, self.buf[rem..Self::BUF_LEN].assume_init_mut());
}
/* Add a null-terminator, whether or not the read was nonsaturating (for SIMD-accelerated unsafe integer read routines).
* This is safe since we spare 8 bytes at the end of the buffer. */
Expand Down Expand Up @@ -196,8 +193,7 @@ impl<const N: usize> Reader<N> {
let mut total = 0;
loop {
let len = self.len - self.off;
let range =
unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[self.off..self.off + len]) };
let range = unsafe { self.buf[self.off..self.off + len].assume_init_ref() };
if let Some(i) = unsafe { position::memchr(range, delim) } {
unsafe { buf.as_mut_vec() }.extend_from_slice(&range[..i]);
self.off += i + 1;
Expand All @@ -213,7 +209,7 @@ impl<const N: usize> Reader<N> {
}
}
pub fn remain(&self) -> &[u8] {
unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[self.off..self.len]) }
unsafe { self.buf[self.off..self.len].assume_init_ref() }
}
pub fn discard(&mut self, until: u8) -> usize {
let mut len = 0;
Expand Down Expand Up @@ -471,7 +467,7 @@ impl<const N: usize> ReaderTrait for Reader<N> {
if end == self.off {
f64::NAN
} else {
let s_u8 = unsafe { MaybeUninit::slice_assume_init_ref(&self.buf[self.off..end]) };
let s_u8 = unsafe { self.buf[self.off..end].assume_init_ref() };
let s = unsafe { core::str::from_utf8_unchecked(s_u8) };
let out = f64::from_str(s);
self.skip_until_whitespace();
Expand Down
18 changes: 10 additions & 8 deletions basm-std/src/platform/io/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,7 @@ impl<const N: usize> Writer<N> {
}
/// Flushes the buffer of the current `Writer`.
pub fn flush(&mut self) {
services::write_stdio(1, unsafe {
MaybeUninit::slice_assume_init_ref(&self.buf[..self.off])
});
services::write_stdio(1, unsafe { self.buf[..self.off].assume_init_ref() });
self.off = 0;
}
/// Flushes the buffer of the current `Writer` if readahead plus the current offset exceeds the buffer length,
Expand Down Expand Up @@ -163,7 +161,8 @@ impl<const N: usize> Writer<N> {
while !s.is_empty() {
let rem = s.len().min(self.buf[self.off..].len());
unsafe {
MaybeUninit::slice_assume_init_mut(&mut self.buf[self.off..self.off + rem])
self.buf[self.off..self.off + rem]
.assume_init_mut()
.copy_from_slice(&s[..rem]);
}
self.off += rem;
Expand Down Expand Up @@ -267,7 +266,8 @@ impl<const N: usize> Writer<N> {
}
let len = 16 - off;
unsafe {
MaybeUninit::slice_assume_init_mut(&mut self.buf[self.off..self.off + len])
self.buf[self.off..self.off + len]
.assume_init_mut()
.copy_from_slice(&b128.0[off..]);
}
self.off += len;
Expand Down Expand Up @@ -329,13 +329,15 @@ impl<const N: usize> Writer<N> {
}
let len = 16 - hioff;
unsafe {
MaybeUninit::slice_assume_init_mut(&mut self.buf[self.off..self.off + len])
self.buf[self.off..self.off + len]
.assume_init_mut()
.copy_from_slice(&hi128.0[hioff..]);
}
self.off += len;
let len = 16 - looff;
unsafe {
MaybeUninit::slice_assume_init_mut(&mut self.buf[self.off..self.off + len])
self.buf[self.off..self.off + len]
.assume_init_mut()
.copy_from_slice(&lo128.0[looff..]);
}
self.off += len;
Expand Down Expand Up @@ -392,7 +394,7 @@ impl<const N: usize> Writer<N> {
buf[offset].write(b'0' + (n % 10) as u8);
n /= 10;
}
self.bytes(unsafe { MaybeUninit::slice_assume_init_ref(&buf[offset..]) });
self.bytes(unsafe { buf[offset..].assume_init_ref() });
}
#[cfg(target_pointer_width = "32")]
pub fn isize(&mut self, n: isize) {
Expand Down

0 comments on commit 975634a

Please sign in to comment.