Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: Rename ReadBuf methods #2945

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion tokio-test/src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl Inner {
let n = cmp::min(dst.remaining(), data.len());

// Copy the data into the `dst` slice
dst.append(&data[..n]);
dst.put_slice(&data[..n]);

// Drain the data from the source
data.drain(..n);
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/compat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ where
cx,
slice
))?;
buf.add_filled(n);
buf.advance(n);
Poll::Ready(Ok(()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/src/io/stream_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ where
Poll::Pending => return Poll::Pending,
};
let len = std::cmp::min(inner_buf.len(), buf.remaining());
buf.append(&inner_buf[..len]);
buf.put_slice(&inner_buf[..len]);

self.consume(len);
Poll::Ready(Ok(()))
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/framed_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ impl AsyncRead for Mock {
match self.calls.pop_front() {
Some(Ok(data)) => {
debug_assert!(buf.remaining() >= data.len());
buf.append(&data);
buf.put_slice(&data);
Ready(Ok(()))
}
Some(Err(ref e)) if e.kind() == WouldBlock => Pending,
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/io_reader_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl AsyncRead for Reader {
for x in &mut buf.initialize_unfilled_to(n)[..n] {
*x = 0;
}
buf.add_filled(n);
buf.advance(n);
this.remaining -= n;
Poll::Ready(Ok(()))
} else {
Expand Down
2 changes: 1 addition & 1 deletion tokio-util/tests/length_delimited.rs
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@ impl AsyncRead for Mock {
match self.calls.pop_front() {
Some(Ready(Ok(Op::Data(data)))) => {
debug_assert!(dst.remaining() >= data.len());
dst.append(&data);
dst.put_slice(&data);
Ready(Ok(()))
}
Some(Ready(Ok(_))) => panic!(),
Expand Down
4 changes: 2 additions & 2 deletions tokio/src/io/async_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ impl AsyncRead for &[u8] {
) -> Poll<io::Result<()>> {
let amt = std::cmp::min(self.len(), buf.remaining());
let (a, b) = self.split_at(amt);
buf.append(a);
buf.put_slice(a);
*self = b;
Poll::Ready(Ok(()))
}
Expand All @@ -121,7 +121,7 @@ impl<T: AsRef<[u8]> + Unpin> AsyncRead for io::Cursor<T> {
let amt = std::cmp::min(slice.len() - start, buf.remaining());
// Add won't overflow because of pos check above.
let end = start + amt;
buf.append(&slice[start..end]);
buf.put_slice(&slice[start..end]);
self.set_position(end as u64);

Poll::Ready(Ok(()))
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ impl Buf {

pub(crate) fn copy_to(&mut self, dst: &mut ReadBuf<'_>) -> usize {
let n = cmp::min(self.len(), dst.remaining());
dst.append(&self.bytes()[..n]);
dst.put_slice(&self.bytes()[..n]);
self.pos += n;

if self.pos == self.buf.len() {
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/poll_evented.rs
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ impl<E: Source + Read + Unpin> AsyncRead for PollEvented<E> {
}

return Poll::Ready(r.map(|n| {
buf.add_filled(n);
buf.advance(n);
}));
}
}
Expand Down
6 changes: 3 additions & 3 deletions tokio/src/io/read_buf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,15 +171,15 @@ impl<'a> ReadBuf<'a> {
self.filled = 0;
}

/// Increases the size of the filled region of the buffer.
/// Advances the size of the filled region of the buffer.
///
/// The number of initialized bytes is not changed.
///
/// # Panics
///
/// Panics if the filled region of the buffer would become larger than the initialized region.
#[inline]
pub fn add_filled(&mut self, n: usize) {
pub fn advance(&mut self, n: usize) {
let new = self.filled.checked_add(n).expect("filled overflow");
self.set_filled(new);
}
Expand Down Expand Up @@ -225,7 +225,7 @@ impl<'a> ReadBuf<'a> {
///
/// Panics if `self.remaining()` is less than `buf.len()`.
#[inline]
pub fn append(&mut self, buf: &[u8]) {
pub fn put_slice(&mut self, buf: &[u8]) {
assert!(
self.remaining() >= buf.len(),
"buf.len() must fit in remaining()"
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/buf_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl<R: AsyncRead> AsyncRead for BufReader<R> {
}
let rem = ready!(self.as_mut().poll_fill_buf(cx))?;
let amt = std::cmp::min(rem.len(), buf.remaining());
buf.append(&rem[..amt]);
buf.put_slice(&rem[..amt]);
self.consume(amt);
Poll::Ready(Ok(()))
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl AsyncRead for Pipe {
) -> Poll<std::io::Result<()>> {
if self.buffer.has_remaining() {
let max = self.buffer.remaining().min(buf.remaining());
buf.append(&self.buffer[..max]);
buf.put_slice(&self.buffer[..max]);
self.buffer.advance(max);
if max > 0 {
// The passed `buf` might have been empty, don't wake up if
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/repeat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl AsyncRead for Repeat {
) -> Poll<io::Result<()>> {
// TODO: could be faster, but should we unsafe it?
while buf.remaining() != 0 {
buf.append(&[self.byte]);
buf.put_slice(&[self.byte]);
}
Poll::Ready(Ok(()))
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/io/util/take.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl<R: AsyncRead> AsyncRead for Take<R> {
unsafe {
buf.assume_init(n);
}
buf.add_filled(n);
buf.advance(n);
*me.limit_ -= n as u64;
Poll::Ready(Ok(()))
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/tcp/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ impl TcpStream {
unsafe {
buf.assume_init(n);
}
buf.add_filled(n);
buf.advance(n);
return Poll::Ready(Ok(()));
}
Err(e) => return Poll::Ready(Err(e)),
Expand Down
2 changes: 1 addition & 1 deletion tokio/src/net/unix/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ impl UnixStream {
unsafe {
buf.assume_init(n);
}
buf.add_filled(n);
buf.advance(n);
return Poll::Ready(Ok(()));
}
Err(e) => return Poll::Ready(Err(e)),
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/io_copy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ async fn copy() {
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
if self.0 {
buf.append(b"hello world");
buf.put_slice(b"hello world");
self.0 = false;
Poll::Ready(Ok(()))
} else {
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/io_read.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async fn read() {
assert_eq!(0, self.poll_cnt);
self.poll_cnt += 1;

buf.append(b"hello world");
buf.put_slice(b"hello world");
Poll::Ready(Ok(()))
}
}
Expand Down
2 changes: 1 addition & 1 deletion tokio/tests/io_split.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ impl AsyncRead for RW {
_cx: &mut Context<'_>,
buf: &mut ReadBuf<'_>,
) -> Poll<io::Result<()>> {
buf.append(&[b'z']);
buf.put_slice(&[b'z']);
Poll::Ready(Ok(()))
}
}
Expand Down