mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Rename BorrowedCursor::advance_unchecked to advance
Co-authored-by: Josh Triplett <josh@joshtriplett.org>
This commit is contained in:
@@ -272,7 +272,7 @@ pub unsafe fn as_mut(&mut self) -> &mut [MaybeUninit<u8>] {
|
||||
/// Panics if there are less than `n` bytes initialized.
|
||||
#[unstable(feature = "borrowed_buf_init", issue = "78485")]
|
||||
#[inline]
|
||||
pub fn advance(&mut self, n: usize) -> &mut Self {
|
||||
pub fn advance_checked(&mut self, n: usize) -> &mut Self {
|
||||
// The subtraction cannot underflow by invariant of this type.
|
||||
let init_unfilled = if self.buf.init { self.buf.buf.len() - self.buf.filled } else { 0 };
|
||||
assert!(n <= init_unfilled);
|
||||
@@ -292,7 +292,7 @@ pub fn advance(&mut self, n: usize) -> &mut Self {
|
||||
/// The caller must ensure that the first `n` bytes of the cursor have been properly
|
||||
/// initialised.
|
||||
#[inline]
|
||||
pub unsafe fn advance_unchecked(&mut self, n: usize) -> &mut Self {
|
||||
pub unsafe fn advance(&mut self, n: usize) -> &mut Self {
|
||||
self.buf.filled += n;
|
||||
self
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ fn advance_filled() {
|
||||
let buf: &mut [_] = &mut [0; 16];
|
||||
let mut rbuf: BorrowedBuf<'_> = buf.into();
|
||||
|
||||
rbuf.unfilled().advance(1);
|
||||
rbuf.unfilled().advance_checked(1);
|
||||
|
||||
assert_eq!(rbuf.filled().len(), 1);
|
||||
assert_eq!(rbuf.unfilled().capacity(), 15);
|
||||
@@ -51,7 +51,7 @@ fn clear() {
|
||||
let buf: &mut [_] = &mut [255; 16];
|
||||
let mut rbuf: BorrowedBuf<'_> = buf.into();
|
||||
|
||||
rbuf.unfilled().advance(16);
|
||||
rbuf.unfilled().advance_checked(16);
|
||||
|
||||
assert_eq!(rbuf.filled().len(), 16);
|
||||
assert_eq!(rbuf.unfilled().capacity(), 0);
|
||||
@@ -131,7 +131,7 @@ fn cursor_set_init() {
|
||||
assert!(cursor.is_init());
|
||||
assert_eq!(unsafe { cursor.as_mut().len() }, 16);
|
||||
|
||||
cursor.advance(4);
|
||||
cursor.advance_checked(4);
|
||||
|
||||
assert_eq!(unsafe { cursor.as_mut().len() }, 12);
|
||||
|
||||
@@ -157,7 +157,7 @@ fn cursor_with_unfilled_buf() {
|
||||
assert!(!buf.is_init());
|
||||
|
||||
buf.unfilled().ensure_init();
|
||||
buf.unfilled().advance(4);
|
||||
buf.unfilled().advance_checked(4);
|
||||
});
|
||||
|
||||
assert!(cursor.is_init());
|
||||
|
||||
@@ -570,7 +570,7 @@ pub(crate) fn default_read_buf<F>(read: F, mut cursor: BorrowedCursor<'_>) -> Re
|
||||
F: FnOnce(&mut [u8]) -> Result<usize>,
|
||||
{
|
||||
let n = read(cursor.ensure_init())?;
|
||||
cursor.advance(n);
|
||||
cursor.advance_checked(n);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -3113,7 +3113,7 @@ fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> Result<()> {
|
||||
|
||||
unsafe {
|
||||
// SAFETY: filled bytes have been filled
|
||||
buf.advance_unchecked(filled);
|
||||
buf.advance(filled);
|
||||
}
|
||||
|
||||
self.limit -= filled as u64;
|
||||
|
||||
@@ -283,7 +283,7 @@ fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
// SAFETY: No uninit bytes are being written.
|
||||
unsafe { buf.as_mut() }.write_filled(self.byte);
|
||||
// SAFETY: the entire unfilled portion of buf has been initialized.
|
||||
unsafe { buf.advance_unchecked(buf.capacity()) };
|
||||
unsafe { buf.advance(buf.capacity()) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -33,7 +33,7 @@ pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
)
|
||||
})?;
|
||||
// SAFETY: Exactly `result` bytes have been filled.
|
||||
unsafe { buf.advance_unchecked(result as usize) };
|
||||
unsafe { buf.advance(result as usize) };
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,7 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
|
||||
// SAFETY: `ret` bytes were written to the initialized portion of the buffer
|
||||
unsafe {
|
||||
cursor.advance_unchecked(ret as usize);
|
||||
cursor.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -203,7 +203,7 @@ pub fn read_buf_at(&self, mut cursor: BorrowedCursor<'_>, offset: u64) -> io::Re
|
||||
|
||||
// SAFETY: `ret` bytes were written to the initialized portion of the buffer
|
||||
unsafe {
|
||||
cursor.advance_unchecked(ret as usize);
|
||||
cursor.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -401,7 +401,7 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
|
||||
// Safety: `num_bytes_read` bytes were written to the unfilled
|
||||
// portion of the buffer
|
||||
cursor.advance_unchecked(num_bytes_read);
|
||||
cursor.advance(num_bytes_read);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -142,7 +142,7 @@ fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: i32) -> io::Result
|
||||
)
|
||||
})?;
|
||||
unsafe {
|
||||
buf.advance_unchecked(ret as usize);
|
||||
buf.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -190,7 +190,7 @@ fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Resu
|
||||
netc::recv(self.as_raw_fd(), buf.as_mut().as_mut_ptr().cast(), buf.capacity(), flags)
|
||||
})?;
|
||||
unsafe {
|
||||
buf.advance_unchecked(ret as usize);
|
||||
buf.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Resu
|
||||
)
|
||||
})?;
|
||||
unsafe {
|
||||
buf.advance_unchecked(ret as usize);
|
||||
buf.advance(ret as usize);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -243,7 +243,7 @@ fn recv_with_flags(&self, mut buf: BorrowedCursor<'_>, flags: c_int) -> io::Resu
|
||||
}
|
||||
}
|
||||
_ => {
|
||||
unsafe { buf.advance_unchecked(result as usize) };
|
||||
unsafe { buf.advance(result as usize) };
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ pub fn read_buf(fd: Fd, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
let mut userbuf = alloc::User::<[u8]>::uninitialized(buf.capacity());
|
||||
let len = raw::read(fd, userbuf.as_mut_ptr().cast(), userbuf.len()).from_sgx_result()?;
|
||||
userbuf[..len].copy_to_enclave(&mut buf.as_mut()[..len]);
|
||||
buf.advance_unchecked(len);
|
||||
buf.advance(len);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ pub fn read_buf(&self, mut cursor: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
Ok(read) => {
|
||||
// Safety: `read` bytes were written to the initialized portion of the buffer
|
||||
unsafe {
|
||||
cursor.advance_unchecked(read);
|
||||
cursor.advance(read);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -140,7 +140,7 @@ pub fn read_buf_at(&self, mut cursor: BorrowedCursor<'_>, offset: u64) -> io::Re
|
||||
|
||||
// SAFETY: `read` bytes were written to the initialized portion of the buffer
|
||||
unsafe {
|
||||
cursor.advance_unchecked(read);
|
||||
cursor.advance(read);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -260,7 +260,7 @@ pub fn read_buf(&self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
Err(e) => Err(e),
|
||||
Ok(n) => {
|
||||
unsafe {
|
||||
buf.advance_unchecked(n);
|
||||
buf.advance(n);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
|
||||
fn read_buf(&mut self, mut buf: BorrowedCursor<'_>) -> io::Result<()> {
|
||||
unsafe {
|
||||
let n = abi::sys_read(fileno::STDIN, buf.as_mut().as_mut_ptr().cast(), buf.capacity());
|
||||
buf.advance_unchecked(n);
|
||||
buf.advance(n);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user